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 inline void soc_widget_lock(struct snd_soc_dapm_widget
*w
)
211 if (w
->codec
&& !w
->codec
->using_regmap
)
212 mutex_lock(&w
->codec
->mutex
);
213 else if (w
->platform
)
214 mutex_lock(&w
->platform
->mutex
);
217 static inline void soc_widget_unlock(struct snd_soc_dapm_widget
*w
)
219 if (w
->codec
&& !w
->codec
->using_regmap
)
220 mutex_unlock(&w
->codec
->mutex
);
221 else if (w
->platform
)
222 mutex_unlock(&w
->platform
->mutex
);
225 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget
*w
,
226 unsigned short reg
, unsigned int mask
, unsigned int value
)
229 unsigned int old
, new;
232 if (w
->codec
&& w
->codec
->using_regmap
) {
233 ret
= regmap_update_bits_check(w
->codec
->control_data
,
234 reg
, mask
, value
, &change
);
239 ret
= soc_widget_read(w
, reg
);
241 soc_widget_unlock(w
);
246 new = (old
& ~mask
) | (value
& mask
);
249 ret
= soc_widget_write(w
, reg
, new);
251 soc_widget_unlock(w
);
255 soc_widget_unlock(w
);
262 * snd_soc_dapm_set_bias_level - set the bias level for the system
263 * @dapm: DAPM context
264 * @level: level to configure
266 * Configure the bias (power) levels for the SoC audio device.
268 * Returns 0 for success else error.
270 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
271 enum snd_soc_bias_level level
)
273 struct snd_soc_card
*card
= dapm
->card
;
276 trace_snd_soc_bias_level_start(card
, level
);
278 if (card
&& card
->set_bias_level
)
279 ret
= card
->set_bias_level(card
, dapm
, level
);
284 if (dapm
->codec
->driver
->set_bias_level
)
285 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
288 dapm
->bias_level
= level
;
293 if (card
&& card
->set_bias_level_post
)
294 ret
= card
->set_bias_level_post(card
, dapm
, level
);
296 trace_snd_soc_bias_level_done(card
, level
);
301 /* set up initial codec paths */
302 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
303 struct snd_soc_dapm_path
*p
, int i
)
306 case snd_soc_dapm_switch
:
307 case snd_soc_dapm_mixer
:
308 case snd_soc_dapm_mixer_named_ctl
: {
310 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
311 w
->kcontrol_news
[i
].private_value
;
312 unsigned int reg
= mc
->reg
;
313 unsigned int shift
= mc
->shift
;
315 unsigned int mask
= (1 << fls(max
)) - 1;
316 unsigned int invert
= mc
->invert
;
318 val
= soc_widget_read(w
, reg
);
319 val
= (val
>> shift
) & mask
;
321 if ((invert
&& !val
) || (!invert
&& val
))
327 case snd_soc_dapm_mux
: {
328 struct soc_enum
*e
= (struct soc_enum
*)
329 w
->kcontrol_news
[i
].private_value
;
330 int val
, item
, bitmask
;
332 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
334 val
= soc_widget_read(w
, e
->reg
);
335 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
338 for (i
= 0; i
< e
->max
; i
++) {
339 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
344 case snd_soc_dapm_virt_mux
: {
345 struct soc_enum
*e
= (struct soc_enum
*)
346 w
->kcontrol_news
[i
].private_value
;
349 /* since a virtual mux has no backing registers to
350 * decide which path to connect, it will try to match
351 * with the first enumeration. This is to ensure
352 * that the default mux choice (the first) will be
353 * correctly powered up during initialization.
355 if (!strcmp(p
->name
, e
->texts
[0]))
359 case snd_soc_dapm_value_mux
: {
360 struct soc_enum
*e
= (struct soc_enum
*)
361 w
->kcontrol_news
[i
].private_value
;
364 val
= soc_widget_read(w
, e
->reg
);
365 val
= (val
>> e
->shift_l
) & e
->mask
;
366 for (item
= 0; item
< e
->max
; item
++) {
367 if (val
== e
->values
[item
])
372 for (i
= 0; i
< e
->max
; i
++) {
373 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
378 /* does not affect routing - always connected */
379 case snd_soc_dapm_pga
:
380 case snd_soc_dapm_out_drv
:
381 case snd_soc_dapm_output
:
382 case snd_soc_dapm_adc
:
383 case snd_soc_dapm_input
:
384 case snd_soc_dapm_siggen
:
385 case snd_soc_dapm_dac
:
386 case snd_soc_dapm_micbias
:
387 case snd_soc_dapm_vmid
:
388 case snd_soc_dapm_supply
:
389 case snd_soc_dapm_regulator_supply
:
390 case snd_soc_dapm_aif_in
:
391 case snd_soc_dapm_aif_out
:
392 case snd_soc_dapm_dai
:
393 case snd_soc_dapm_hp
:
394 case snd_soc_dapm_mic
:
395 case snd_soc_dapm_spk
:
396 case snd_soc_dapm_line
:
399 /* does affect routing - dynamically connected */
400 case snd_soc_dapm_pre
:
401 case snd_soc_dapm_post
:
407 /* connect mux widget to its interconnecting audio paths */
408 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
409 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
410 struct snd_soc_dapm_path
*path
, const char *control_name
,
411 const struct snd_kcontrol_new
*kcontrol
)
413 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
416 for (i
= 0; i
< e
->max
; i
++) {
417 if (!(strcmp(control_name
, e
->texts
[i
]))) {
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
= (char*)e
->texts
[i
];
422 dapm_set_path_status(dest
, path
, 0);
430 /* connect mixer widget to its interconnecting audio paths */
431 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
432 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
433 struct snd_soc_dapm_path
*path
, const char *control_name
)
437 /* search for mixer kcontrol */
438 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
439 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
440 list_add(&path
->list
, &dapm
->card
->paths
);
441 list_add(&path
->list_sink
, &dest
->sources
);
442 list_add(&path
->list_source
, &src
->sinks
);
443 path
->name
= dest
->kcontrol_news
[i
].name
;
444 dapm_set_path_status(dest
, path
, i
);
451 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
452 struct snd_soc_dapm_widget
*kcontrolw
,
453 const struct snd_kcontrol_new
*kcontrol_new
,
454 struct snd_kcontrol
**kcontrol
)
456 struct snd_soc_dapm_widget
*w
;
461 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
462 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
464 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
465 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
467 *kcontrol
= w
->kcontrols
[i
];
476 /* create new dapm mixer control */
477 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
479 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
481 size_t name_len
, prefix_len
;
482 struct snd_soc_dapm_path
*path
;
483 struct snd_card
*card
= dapm
->card
->snd_card
;
485 struct snd_soc_dapm_widget_list
*wlist
;
489 prefix
= dapm
->codec
->name_prefix
;
494 prefix_len
= strlen(prefix
) + 1;
499 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
502 list_for_each_entry(path
, &w
->sources
, list_sink
) {
504 /* mixer/mux paths name must match control name */
505 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
508 if (w
->kcontrols
[i
]) {
509 path
->kcontrol
= w
->kcontrols
[i
];
513 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
514 sizeof(struct snd_soc_dapm_widget
*),
515 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
518 "asoc: can't allocate widget list for %s\n",
522 wlist
->num_widgets
= 1;
523 wlist
->widgets
[0] = w
;
525 /* add dapm control with long name.
526 * for dapm_mixer this is the concatenation of the
527 * mixer and kcontrol name.
528 * for dapm_mixer_named_ctl this is simply the
531 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
532 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
533 name_len
+= 1 + strlen(w
->name
);
535 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
537 if (path
->long_name
== NULL
) {
544 /* The control will get a prefix from
545 * the control creation process but
546 * we're also using the same prefix
547 * for widgets so cut the prefix off
548 * the front of the widget name.
550 snprintf((char *)path
->long_name
, name_len
,
551 "%s %s", w
->name
+ prefix_len
,
552 w
->kcontrol_news
[i
].name
);
554 case snd_soc_dapm_mixer_named_ctl
:
555 snprintf((char *)path
->long_name
, name_len
,
556 "%s", w
->kcontrol_news
[i
].name
);
560 ((char *)path
->long_name
)[name_len
- 1] = '\0';
562 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
563 wlist
, path
->long_name
,
565 ret
= snd_ctl_add(card
, path
->kcontrol
);
568 "asoc: failed to add dapm kcontrol %s: %d\n",
569 path
->long_name
, ret
);
571 kfree(path
->long_name
);
572 path
->long_name
= NULL
;
575 w
->kcontrols
[i
] = path
->kcontrol
;
581 /* create new dapm mux control */
582 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
584 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
585 struct snd_soc_dapm_path
*path
= NULL
;
586 struct snd_kcontrol
*kcontrol
;
587 struct snd_card
*card
= dapm
->card
->snd_card
;
591 struct snd_soc_dapm_widget_list
*wlist
;
592 int shared
, wlistentries
;
596 if (w
->num_kcontrols
!= 1) {
598 "asoc: mux %s has incorrect number of controls\n",
603 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
606 wlist
= kcontrol
->private_data
;
607 wlistentries
= wlist
->num_widgets
+ 1;
612 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
613 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
614 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
617 "asoc: can't allocate widget list for %s\n", w
->name
);
620 wlist
->num_widgets
= wlistentries
;
621 wlist
->widgets
[wlistentries
- 1] = w
;
625 prefix
= dapm
->codec
->name_prefix
;
630 name
= w
->kcontrol_news
[0].name
;
635 prefix_len
= strlen(prefix
) + 1;
641 * The control will get a prefix from the control creation
642 * process but we're also using the same prefix for widgets so
643 * cut the prefix off the front of the widget name.
645 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
646 name
+ prefix_len
, prefix
);
647 ret
= snd_ctl_add(card
, kcontrol
);
649 dev_err(dapm
->dev
, "failed to add kcontrol %s: %d\n",
656 kcontrol
->private_data
= wlist
;
658 w
->kcontrols
[0] = kcontrol
;
660 list_for_each_entry(path
, &w
->sources
, list_sink
)
661 path
->kcontrol
= kcontrol
;
666 /* create new dapm volume control */
667 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
669 if (w
->num_kcontrols
)
670 dev_err(w
->dapm
->dev
,
671 "asoc: PGA controls not supported: '%s'\n", w
->name
);
676 /* reset 'walked' bit for each dapm path */
677 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
679 struct snd_soc_dapm_path
*p
;
681 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
685 /* We implement power down on suspend by checking the power state of
686 * the ALSA card - when we are suspending the ALSA state for the card
689 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
691 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
694 case SNDRV_CTL_POWER_D3hot
:
695 case SNDRV_CTL_POWER_D3cold
:
696 if (widget
->ignore_suspend
)
697 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
699 return widget
->ignore_suspend
;
706 * Recursively check for a completed path to an active or physically connected
707 * output widget. Returns number of complete paths.
709 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
711 struct snd_soc_dapm_path
*path
;
714 if (widget
->outputs
>= 0)
715 return widget
->outputs
;
717 DAPM_UPDATE_STAT(widget
, path_checks
);
719 switch (widget
->id
) {
720 case snd_soc_dapm_supply
:
721 case snd_soc_dapm_regulator_supply
:
727 switch (widget
->id
) {
728 case snd_soc_dapm_adc
:
729 case snd_soc_dapm_aif_out
:
730 case snd_soc_dapm_dai
:
731 if (widget
->active
) {
732 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
733 return widget
->outputs
;
739 if (widget
->connected
) {
740 /* connected pin ? */
741 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
742 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
743 return widget
->outputs
;
746 /* connected jack or spk ? */
747 if (widget
->id
== snd_soc_dapm_hp
||
748 widget
->id
== snd_soc_dapm_spk
||
749 (widget
->id
== snd_soc_dapm_line
&&
750 !list_empty(&widget
->sources
))) {
751 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
752 return widget
->outputs
;
756 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
757 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
765 if (path
->sink
&& path
->connect
) {
767 con
+= is_connected_output_ep(path
->sink
);
771 widget
->outputs
= con
;
777 * Recursively check for a completed path to an active or physically connected
778 * input widget. Returns number of complete paths.
780 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
782 struct snd_soc_dapm_path
*path
;
785 if (widget
->inputs
>= 0)
786 return widget
->inputs
;
788 DAPM_UPDATE_STAT(widget
, path_checks
);
790 switch (widget
->id
) {
791 case snd_soc_dapm_supply
:
792 case snd_soc_dapm_regulator_supply
:
798 /* active stream ? */
799 switch (widget
->id
) {
800 case snd_soc_dapm_dac
:
801 case snd_soc_dapm_aif_in
:
802 case snd_soc_dapm_dai
:
803 if (widget
->active
) {
804 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
805 return widget
->inputs
;
811 if (widget
->connected
) {
812 /* connected pin ? */
813 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
814 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
815 return widget
->inputs
;
818 /* connected VMID/Bias for lower pops */
819 if (widget
->id
== snd_soc_dapm_vmid
) {
820 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
821 return widget
->inputs
;
824 /* connected jack ? */
825 if (widget
->id
== snd_soc_dapm_mic
||
826 (widget
->id
== snd_soc_dapm_line
&&
827 !list_empty(&widget
->sinks
))) {
828 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
829 return widget
->inputs
;
832 /* signal generator */
833 if (widget
->id
== snd_soc_dapm_siggen
) {
834 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
835 return widget
->inputs
;
839 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
840 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
848 if (path
->source
&& path
->connect
) {
850 con
+= is_connected_input_ep(path
->source
);
854 widget
->inputs
= con
;
860 * Handler for generic register modifier widget.
862 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
863 struct snd_kcontrol
*kcontrol
, int event
)
867 if (SND_SOC_DAPM_EVENT_ON(event
))
872 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
873 w
->mask
<< w
->shift
, val
<< w
->shift
);
877 EXPORT_SYMBOL_GPL(dapm_reg_event
);
880 * Handler for regulator supply widget.
882 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
883 struct snd_kcontrol
*kcontrol
, int event
)
885 if (SND_SOC_DAPM_EVENT_ON(event
))
886 return regulator_enable(w
->regulator
);
888 return regulator_disable_deferred(w
->regulator
, w
->shift
);
890 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
892 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
894 if (w
->power_checked
)
900 w
->new_power
= w
->power_check(w
);
902 w
->power_checked
= true;
907 /* Generic check to see if a widget should be powered.
909 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
913 DAPM_UPDATE_STAT(w
, power_checks
);
915 in
= is_connected_input_ep(w
);
916 dapm_clear_walk(w
->dapm
);
917 out
= is_connected_output_ep(w
);
918 dapm_clear_walk(w
->dapm
);
919 return out
!= 0 && in
!= 0;
922 static int dapm_dai_check_power(struct snd_soc_dapm_widget
*w
)
924 DAPM_UPDATE_STAT(w
, power_checks
);
929 /* Check to see if an ADC has power */
930 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
934 DAPM_UPDATE_STAT(w
, power_checks
);
937 in
= is_connected_input_ep(w
);
938 dapm_clear_walk(w
->dapm
);
941 return dapm_generic_check_power(w
);
945 /* Check to see if a DAC has power */
946 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
950 DAPM_UPDATE_STAT(w
, power_checks
);
953 out
= is_connected_output_ep(w
);
954 dapm_clear_walk(w
->dapm
);
957 return dapm_generic_check_power(w
);
961 /* Check to see if a power supply is needed */
962 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
964 struct snd_soc_dapm_path
*path
;
966 DAPM_UPDATE_STAT(w
, power_checks
);
968 /* Check if one of our outputs is connected */
969 list_for_each_entry(path
, &w
->sinks
, list_source
) {
970 DAPM_UPDATE_STAT(w
, neighbour_checks
);
975 if (path
->connected
&&
976 !path
->connected(path
->source
, path
->sink
))
982 if (dapm_widget_power_check(path
->sink
))
986 dapm_clear_walk(w
->dapm
);
991 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
996 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
997 struct snd_soc_dapm_widget
*b
,
1005 sort
= dapm_down_seq
;
1007 if (sort
[a
->id
] != sort
[b
->id
])
1008 return sort
[a
->id
] - sort
[b
->id
];
1009 if (a
->subseq
!= b
->subseq
) {
1011 return a
->subseq
- b
->subseq
;
1013 return b
->subseq
- a
->subseq
;
1015 if (a
->reg
!= b
->reg
)
1016 return a
->reg
- b
->reg
;
1017 if (a
->dapm
!= b
->dapm
)
1018 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1023 /* Insert a widget in order into a DAPM power sequence. */
1024 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1025 struct list_head
*list
,
1028 struct snd_soc_dapm_widget
*w
;
1030 list_for_each_entry(w
, list
, power_list
)
1031 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1032 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1036 list_add_tail(&new_widget
->power_list
, list
);
1039 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
1040 struct snd_soc_dapm_widget
*w
, int event
)
1042 struct snd_soc_card
*card
= dapm
->card
;
1043 const char *ev_name
;
1047 case SND_SOC_DAPM_PRE_PMU
:
1048 ev_name
= "PRE_PMU";
1051 case SND_SOC_DAPM_POST_PMU
:
1052 ev_name
= "POST_PMU";
1055 case SND_SOC_DAPM_PRE_PMD
:
1056 ev_name
= "PRE_PMD";
1059 case SND_SOC_DAPM_POST_PMD
:
1060 ev_name
= "POST_PMD";
1068 if (w
->power
!= power
)
1071 if (w
->event
&& (w
->event_flags
& event
)) {
1072 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1074 trace_snd_soc_dapm_widget_event_start(w
, event
);
1075 ret
= w
->event(w
, NULL
, event
);
1076 trace_snd_soc_dapm_widget_event_done(w
, event
);
1078 pr_err("%s: %s event failed: %d\n",
1079 ev_name
, w
->name
, ret
);
1083 /* Apply the coalesced changes from a DAPM sequence */
1084 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
1085 struct list_head
*pending
)
1087 struct snd_soc_card
*card
= dapm
->card
;
1088 struct snd_soc_dapm_widget
*w
;
1090 unsigned int value
= 0;
1091 unsigned int mask
= 0;
1092 unsigned int cur_mask
;
1094 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1097 list_for_each_entry(w
, pending
, power_list
) {
1098 cur_mask
= 1 << w
->shift
;
1099 BUG_ON(reg
!= w
->reg
);
1110 pop_dbg(dapm
->dev
, card
->pop_time
,
1111 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1112 w
->name
, reg
, value
, mask
);
1114 /* Check for events */
1115 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
1116 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
1120 /* Any widget will do, they should all be updating the
1123 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1126 pop_dbg(dapm
->dev
, card
->pop_time
,
1127 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1128 value
, mask
, reg
, card
->pop_time
);
1129 pop_wait(card
->pop_time
);
1130 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1133 list_for_each_entry(w
, pending
, power_list
) {
1134 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
1135 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
1139 /* Apply a DAPM power sequence.
1141 * We walk over a pre-sorted list of widgets to apply power to. In
1142 * order to minimise the number of writes to the device required
1143 * multiple widgets will be updated in a single write where possible.
1144 * Currently anything that requires more than a single write is not
1147 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
1148 struct list_head
*list
, int event
, bool power_up
)
1150 struct snd_soc_dapm_widget
*w
, *n
;
1153 int cur_subseq
= -1;
1154 int cur_reg
= SND_SOC_NOPM
;
1155 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1162 sort
= dapm_down_seq
;
1164 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1167 /* Do we need to apply any queued changes? */
1168 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1169 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1170 if (!list_empty(&pending
))
1171 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1173 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1174 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1175 if (sort
[i
] == cur_sort
)
1176 cur_dapm
->seq_notifier(cur_dapm
,
1181 INIT_LIST_HEAD(&pending
);
1183 cur_subseq
= INT_MIN
;
1184 cur_reg
= SND_SOC_NOPM
;
1189 case snd_soc_dapm_pre
:
1191 list_for_each_entry_safe_continue(w
, n
, list
,
1194 if (event
== SND_SOC_DAPM_STREAM_START
)
1196 NULL
, SND_SOC_DAPM_PRE_PMU
);
1197 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1199 NULL
, SND_SOC_DAPM_PRE_PMD
);
1202 case snd_soc_dapm_post
:
1204 list_for_each_entry_safe_continue(w
, n
, list
,
1207 if (event
== SND_SOC_DAPM_STREAM_START
)
1209 NULL
, SND_SOC_DAPM_POST_PMU
);
1210 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1212 NULL
, SND_SOC_DAPM_POST_PMD
);
1216 /* Queue it up for application */
1217 cur_sort
= sort
[w
->id
];
1218 cur_subseq
= w
->subseq
;
1221 list_move(&w
->power_list
, &pending
);
1226 dev_err(w
->dapm
->dev
,
1227 "Failed to apply widget power: %d\n", ret
);
1230 if (!list_empty(&pending
))
1231 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1233 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1234 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1235 if (sort
[i
] == cur_sort
)
1236 cur_dapm
->seq_notifier(cur_dapm
,
1241 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1243 struct snd_soc_dapm_update
*update
= dapm
->update
;
1244 struct snd_soc_dapm_widget
*w
;
1253 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1254 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1256 pr_err("%s DAPM pre-event failed: %d\n",
1260 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1263 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1266 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1267 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1269 pr_err("%s DAPM post-event failed: %d\n",
1274 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1275 * they're changing state.
1277 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1279 struct snd_soc_dapm_context
*d
= data
;
1282 /* If we're off and we're not supposed to be go into STANDBY */
1283 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1284 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1286 pm_runtime_get_sync(d
->dev
);
1288 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1291 "Failed to turn on bias: %d\n", ret
);
1294 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1295 if (d
->bias_level
!= d
->target_bias_level
) {
1296 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1299 "Failed to prepare bias: %d\n", ret
);
1303 /* Async callback run prior to DAPM sequences - brings to their final
1306 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1308 struct snd_soc_dapm_context
*d
= data
;
1311 /* If we just powered the last thing off drop to standby bias */
1312 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1313 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1314 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1315 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1317 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1321 /* If we're in standby and can support bias off then do that */
1322 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1323 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1324 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1326 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1329 pm_runtime_put(d
->dev
);
1332 /* If we just powered up then move to active bias */
1333 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1334 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1335 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1337 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1342 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1343 bool power
, bool connect
)
1345 /* If a connection is being made or broken then that update
1346 * will have marked the peer dirty, otherwise the widgets are
1347 * not connected and this update has no impact. */
1351 /* If the peer is already in the state we're moving to then we
1352 * won't have an impact on it. */
1353 if (power
!= peer
->power
)
1354 dapm_mark_dirty(peer
, "peer state change");
1357 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1358 struct list_head
*up_list
,
1359 struct list_head
*down_list
)
1361 struct snd_soc_dapm_path
*path
;
1363 if (w
->power
== power
)
1366 trace_snd_soc_dapm_widget_power(w
, power
);
1368 /* If we changed our power state perhaps our neigbours changed
1371 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1373 dapm_widget_set_peer_power(path
->source
, power
,
1378 case snd_soc_dapm_supply
:
1379 case snd_soc_dapm_regulator_supply
:
1380 /* Supplies can't affect their outputs, only their inputs */
1383 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1385 dapm_widget_set_peer_power(path
->sink
, power
,
1393 dapm_seq_insert(w
, up_list
, true);
1395 dapm_seq_insert(w
, down_list
, false);
1400 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1401 struct list_head
*up_list
,
1402 struct list_head
*down_list
)
1407 case snd_soc_dapm_pre
:
1408 dapm_seq_insert(w
, down_list
, false);
1410 case snd_soc_dapm_post
:
1411 dapm_seq_insert(w
, up_list
, true);
1415 power
= dapm_widget_power_check(w
);
1417 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1423 * Scan each dapm widget for complete audio path.
1424 * A complete path is a route that has valid endpoints i.e.:-
1426 * o DAC to output pin.
1427 * o Input Pin to ADC.
1428 * o Input pin to Output pin (bypass, sidetone)
1429 * o DAC to ADC (loopback).
1431 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1433 struct snd_soc_card
*card
= dapm
->card
;
1434 struct snd_soc_dapm_widget
*w
;
1435 struct snd_soc_dapm_context
*d
;
1437 LIST_HEAD(down_list
);
1438 LIST_HEAD(async_domain
);
1439 enum snd_soc_bias_level bias
;
1441 trace_snd_soc_dapm_start(card
);
1443 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1444 if (d
->idle_bias_off
)
1445 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1447 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1452 /* Check which widgets we need to power and store them in
1453 * lists indicating if they should be powered up or down. We
1454 * only check widgets that have been flagged as dirty but note
1455 * that new widgets may be added to the dirty list while we
1458 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1459 dapm_power_one_widget(w
, &up_list
, &down_list
);
1462 list_for_each_entry(w
, &card
->widgets
, list
) {
1463 list_del_init(&w
->dirty
);
1468 /* Supplies and micbiases only bring the
1469 * context up to STANDBY as unless something
1470 * else is active and passing audio they
1471 * generally don't require full power. Signal
1472 * generators are virtual pins and have no
1473 * power impact themselves.
1476 case snd_soc_dapm_siggen
:
1478 case snd_soc_dapm_supply
:
1479 case snd_soc_dapm_regulator_supply
:
1480 case snd_soc_dapm_micbias
:
1481 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1482 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1485 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1492 /* Force all contexts in the card to the same bias state if
1493 * they're not ground referenced.
1495 bias
= SND_SOC_BIAS_OFF
;
1496 list_for_each_entry(d
, &card
->dapm_list
, list
)
1497 if (d
->target_bias_level
> bias
)
1498 bias
= d
->target_bias_level
;
1499 list_for_each_entry(d
, &card
->dapm_list
, list
)
1500 if (!d
->idle_bias_off
)
1501 d
->target_bias_level
= bias
;
1503 trace_snd_soc_dapm_walk_done(card
);
1505 /* Run all the bias changes in parallel */
1506 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1507 async_schedule_domain(dapm_pre_sequence_async
, d
,
1509 async_synchronize_full_domain(&async_domain
);
1511 /* Power down widgets first; try to avoid amplifying pops. */
1512 dapm_seq_run(dapm
, &down_list
, event
, false);
1514 dapm_widget_update(dapm
);
1517 dapm_seq_run(dapm
, &up_list
, event
, true);
1519 /* Run all the bias changes in parallel */
1520 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1521 async_schedule_domain(dapm_post_sequence_async
, d
,
1523 async_synchronize_full_domain(&async_domain
);
1525 /* do we need to notify any clients that DAPM event is complete */
1526 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1527 if (d
->stream_event
)
1528 d
->stream_event(d
, event
);
1531 pop_dbg(dapm
->dev
, card
->pop_time
,
1532 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1533 pop_wait(card
->pop_time
);
1535 trace_snd_soc_dapm_done(card
);
1540 #ifdef CONFIG_DEBUG_FS
1541 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1543 file
->private_data
= inode
->i_private
;
1547 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1548 char __user
*user_buf
,
1549 size_t count
, loff_t
*ppos
)
1551 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1555 struct snd_soc_dapm_path
*p
= NULL
;
1557 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1561 in
= is_connected_input_ep(w
);
1562 dapm_clear_walk(w
->dapm
);
1563 out
= is_connected_output_ep(w
);
1564 dapm_clear_walk(w
->dapm
);
1566 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1567 w
->name
, w
->power
? "On" : "Off",
1568 w
->force
? " (forced)" : "", in
, out
);
1571 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1572 " - R%d(0x%x) bit %d",
1573 w
->reg
, w
->reg
, w
->shift
);
1575 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1578 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1580 w
->active
? "active" : "inactive");
1582 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1583 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1587 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1588 " in \"%s\" \"%s\"\n",
1589 p
->name
? p
->name
: "static",
1592 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1593 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1597 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1598 " out \"%s\" \"%s\"\n",
1599 p
->name
? p
->name
: "static",
1603 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1609 static const struct file_operations dapm_widget_power_fops
= {
1610 .open
= dapm_widget_power_open_file
,
1611 .read
= dapm_widget_power_read_file
,
1612 .llseek
= default_llseek
,
1615 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1617 file
->private_data
= inode
->i_private
;
1621 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1622 size_t count
, loff_t
*ppos
)
1624 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1627 switch (dapm
->bias_level
) {
1628 case SND_SOC_BIAS_ON
:
1631 case SND_SOC_BIAS_PREPARE
:
1632 level
= "Prepare\n";
1634 case SND_SOC_BIAS_STANDBY
:
1635 level
= "Standby\n";
1637 case SND_SOC_BIAS_OFF
:
1642 level
= "Unknown\n";
1646 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1650 static const struct file_operations dapm_bias_fops
= {
1651 .open
= dapm_bias_open_file
,
1652 .read
= dapm_bias_read_file
,
1653 .llseek
= default_llseek
,
1656 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1657 struct dentry
*parent
)
1661 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1663 if (!dapm
->debugfs_dapm
) {
1665 "Failed to create DAPM debugfs directory\n");
1669 d
= debugfs_create_file("bias_level", 0444,
1670 dapm
->debugfs_dapm
, dapm
,
1674 "ASoC: Failed to create bias level debugfs file\n");
1677 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1679 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1682 if (!dapm
->debugfs_dapm
|| !w
->name
)
1685 d
= debugfs_create_file(w
->name
, 0444,
1686 dapm
->debugfs_dapm
, w
,
1687 &dapm_widget_power_fops
);
1689 dev_warn(w
->dapm
->dev
,
1690 "ASoC: Failed to create %s debugfs file\n",
1694 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1696 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1700 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1701 struct dentry
*parent
)
1705 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1709 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1715 /* test and update the power status of a mux widget */
1716 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1717 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1719 struct snd_soc_dapm_path
*path
;
1722 if (widget
->id
!= snd_soc_dapm_mux
&&
1723 widget
->id
!= snd_soc_dapm_virt_mux
&&
1724 widget
->id
!= snd_soc_dapm_value_mux
)
1727 /* find dapm widget path assoc with kcontrol */
1728 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1729 if (path
->kcontrol
!= kcontrol
)
1732 if (!path
->name
|| !e
->texts
[mux
])
1736 /* we now need to match the string in the enum to the path */
1737 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
1738 path
->connect
= 1; /* new connection */
1739 dapm_mark_dirty(path
->source
, "mux connection");
1742 dapm_mark_dirty(path
->source
,
1743 "mux disconnection");
1744 path
->connect
= 0; /* old connection must be powered down */
1749 dapm_mark_dirty(widget
, "mux change");
1750 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1756 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1757 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1759 struct snd_soc_card
*card
= widget
->dapm
->card
;
1762 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1763 ret
= soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
1764 mutex_unlock(&card
->dapm_mutex
);
1767 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
1769 /* test and update the power status of a mixer or switch widget */
1770 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1771 struct snd_kcontrol
*kcontrol
, int connect
)
1773 struct snd_soc_dapm_path
*path
;
1776 if (widget
->id
!= snd_soc_dapm_mixer
&&
1777 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1778 widget
->id
!= snd_soc_dapm_switch
)
1781 /* find dapm widget path assoc with kcontrol */
1782 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1783 if (path
->kcontrol
!= kcontrol
)
1786 /* found, now check type */
1788 path
->connect
= connect
;
1789 dapm_mark_dirty(path
->source
, "mixer connection");
1793 dapm_mark_dirty(widget
, "mixer update");
1794 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1800 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1801 struct snd_kcontrol
*kcontrol
, int connect
)
1803 struct snd_soc_card
*card
= widget
->dapm
->card
;
1806 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1807 ret
= soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
1808 mutex_unlock(&card
->dapm_mutex
);
1811 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
1813 /* show dapm widget status in sys fs */
1814 static ssize_t
dapm_widget_show(struct device
*dev
,
1815 struct device_attribute
*attr
, char *buf
)
1817 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
1818 struct snd_soc_codec
*codec
=rtd
->codec
;
1819 struct snd_soc_dapm_widget
*w
;
1821 char *state
= "not set";
1823 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1824 if (w
->dapm
!= &codec
->dapm
)
1827 /* only display widgets that burnm power */
1829 case snd_soc_dapm_hp
:
1830 case snd_soc_dapm_mic
:
1831 case snd_soc_dapm_spk
:
1832 case snd_soc_dapm_line
:
1833 case snd_soc_dapm_micbias
:
1834 case snd_soc_dapm_dac
:
1835 case snd_soc_dapm_adc
:
1836 case snd_soc_dapm_pga
:
1837 case snd_soc_dapm_out_drv
:
1838 case snd_soc_dapm_mixer
:
1839 case snd_soc_dapm_mixer_named_ctl
:
1840 case snd_soc_dapm_supply
:
1841 case snd_soc_dapm_regulator_supply
:
1843 count
+= sprintf(buf
+ count
, "%s: %s\n",
1844 w
->name
, w
->power
? "On":"Off");
1851 switch (codec
->dapm
.bias_level
) {
1852 case SND_SOC_BIAS_ON
:
1855 case SND_SOC_BIAS_PREPARE
:
1858 case SND_SOC_BIAS_STANDBY
:
1861 case SND_SOC_BIAS_OFF
:
1865 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1870 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1872 int snd_soc_dapm_sys_add(struct device
*dev
)
1874 return device_create_file(dev
, &dev_attr_dapm_widget
);
1877 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1879 device_remove_file(dev
, &dev_attr_dapm_widget
);
1882 /* free all dapm widgets and resources */
1883 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1885 struct snd_soc_dapm_widget
*w
, *next_w
;
1886 struct snd_soc_dapm_path
*p
, *next_p
;
1888 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1889 if (w
->dapm
!= dapm
)
1893 * remove source and sink paths associated to this widget.
1894 * While removing the path, remove reference to it from both
1895 * source and sink widgets so that path is removed only once.
1897 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1898 list_del(&p
->list_sink
);
1899 list_del(&p
->list_source
);
1901 kfree(p
->long_name
);
1904 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1905 list_del(&p
->list_sink
);
1906 list_del(&p
->list_source
);
1908 kfree(p
->long_name
);
1911 kfree(w
->kcontrols
);
1917 static struct snd_soc_dapm_widget
*dapm_find_widget(
1918 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1919 bool search_other_contexts
)
1921 struct snd_soc_dapm_widget
*w
;
1922 struct snd_soc_dapm_widget
*fallback
= NULL
;
1924 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1925 if (!strcmp(w
->name
, pin
)) {
1926 if (w
->dapm
== dapm
)
1933 if (search_other_contexts
)
1939 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1940 const char *pin
, int status
)
1942 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1945 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1949 if (w
->connected
!= status
)
1950 dapm_mark_dirty(w
, "pin configuration");
1952 w
->connected
= status
;
1960 * snd_soc_dapm_sync - scan and power dapm paths
1961 * @dapm: DAPM context
1963 * Walks all dapm audio paths and powers widgets according to their
1964 * stream or path usage.
1966 * Returns 0 for success.
1968 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1973 * Suppress early reports (eg, jacks syncing their state) to avoid
1974 * silly DAPM runs during card startup.
1976 if (!dapm
->card
|| !dapm
->card
->instantiated
)
1979 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1980 ret
= dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1981 mutex_unlock(&dapm
->card
->dapm_mutex
);
1984 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1986 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1987 const struct snd_soc_dapm_route
*route
)
1989 struct snd_soc_dapm_path
*path
;
1990 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1991 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1993 const char *control
= route
->control
;
1995 char prefixed_sink
[80];
1996 char prefixed_source
[80];
1999 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2000 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2001 dapm
->codec
->name_prefix
, route
->sink
);
2002 sink
= prefixed_sink
;
2003 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2004 dapm
->codec
->name_prefix
, route
->source
);
2005 source
= prefixed_source
;
2008 source
= route
->source
;
2012 * find src and dest widgets over all widgets but favor a widget from
2013 * current DAPM context
2015 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2016 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2018 if (w
->dapm
== dapm
)
2022 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2024 if (w
->dapm
== dapm
)
2028 /* use widget from another DAPM context if not found from this */
2034 if (wsource
== NULL
|| wsink
== NULL
)
2037 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2041 path
->source
= wsource
;
2043 path
->connected
= route
->connected
;
2044 INIT_LIST_HEAD(&path
->list
);
2045 INIT_LIST_HEAD(&path
->list_source
);
2046 INIT_LIST_HEAD(&path
->list_sink
);
2048 /* check for external widgets */
2049 if (wsink
->id
== snd_soc_dapm_input
) {
2050 if (wsource
->id
== snd_soc_dapm_micbias
||
2051 wsource
->id
== snd_soc_dapm_mic
||
2052 wsource
->id
== snd_soc_dapm_line
||
2053 wsource
->id
== snd_soc_dapm_output
)
2056 if (wsource
->id
== snd_soc_dapm_output
) {
2057 if (wsink
->id
== snd_soc_dapm_spk
||
2058 wsink
->id
== snd_soc_dapm_hp
||
2059 wsink
->id
== snd_soc_dapm_line
||
2060 wsink
->id
== snd_soc_dapm_input
)
2064 /* connect static paths */
2065 if (control
== NULL
) {
2066 list_add(&path
->list
, &dapm
->card
->paths
);
2067 list_add(&path
->list_sink
, &wsink
->sources
);
2068 list_add(&path
->list_source
, &wsource
->sinks
);
2073 /* connect dynamic paths */
2074 switch (wsink
->id
) {
2075 case snd_soc_dapm_adc
:
2076 case snd_soc_dapm_dac
:
2077 case snd_soc_dapm_pga
:
2078 case snd_soc_dapm_out_drv
:
2079 case snd_soc_dapm_input
:
2080 case snd_soc_dapm_output
:
2081 case snd_soc_dapm_siggen
:
2082 case snd_soc_dapm_micbias
:
2083 case snd_soc_dapm_vmid
:
2084 case snd_soc_dapm_pre
:
2085 case snd_soc_dapm_post
:
2086 case snd_soc_dapm_supply
:
2087 case snd_soc_dapm_regulator_supply
:
2088 case snd_soc_dapm_aif_in
:
2089 case snd_soc_dapm_aif_out
:
2090 case snd_soc_dapm_dai
:
2091 list_add(&path
->list
, &dapm
->card
->paths
);
2092 list_add(&path
->list_sink
, &wsink
->sources
);
2093 list_add(&path
->list_source
, &wsource
->sinks
);
2096 case snd_soc_dapm_mux
:
2097 case snd_soc_dapm_virt_mux
:
2098 case snd_soc_dapm_value_mux
:
2099 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2100 &wsink
->kcontrol_news
[0]);
2104 case snd_soc_dapm_switch
:
2105 case snd_soc_dapm_mixer
:
2106 case snd_soc_dapm_mixer_named_ctl
:
2107 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2111 case snd_soc_dapm_hp
:
2112 case snd_soc_dapm_mic
:
2113 case snd_soc_dapm_line
:
2114 case snd_soc_dapm_spk
:
2115 list_add(&path
->list
, &dapm
->card
->paths
);
2116 list_add(&path
->list_sink
, &wsink
->sources
);
2117 list_add(&path
->list_source
, &wsource
->sinks
);
2124 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
2125 source
, control
, sink
);
2131 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2132 * @dapm: DAPM context
2133 * @route: audio routes
2134 * @num: number of routes
2136 * Connects 2 dapm widgets together via a named audio path. The sink is
2137 * the widget receiving the audio signal, whilst the source is the sender
2138 * of the audio signal.
2140 * Returns 0 for success else error. On error all resources can be freed
2141 * with a call to snd_soc_card_free().
2143 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2144 const struct snd_soc_dapm_route
*route
, int num
)
2148 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2149 for (i
= 0; i
< num
; i
++) {
2150 ret
= snd_soc_dapm_add_route(dapm
, route
);
2152 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
2153 route
->source
, route
->sink
);
2158 mutex_unlock(&dapm
->card
->dapm_mutex
);
2162 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2164 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2165 const struct snd_soc_dapm_route
*route
)
2167 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2170 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2173 struct snd_soc_dapm_path
*path
;
2177 dev_err(dapm
->dev
, "Unable to find source %s for weak route\n",
2183 dev_err(dapm
->dev
, "Unable to find sink %s for weak route\n",
2188 if (route
->control
|| route
->connected
)
2189 dev_warn(dapm
->dev
, "Ignoring control for weak route %s->%s\n",
2190 route
->source
, route
->sink
);
2192 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2193 if (path
->sink
== sink
) {
2200 dev_err(dapm
->dev
, "No path found for weak route %s->%s\n",
2201 route
->source
, route
->sink
);
2203 dev_warn(dapm
->dev
, "%d paths found for weak route %s->%s\n",
2204 count
, route
->source
, route
->sink
);
2210 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2211 * @dapm: DAPM context
2212 * @route: audio routes
2213 * @num: number of routes
2215 * Mark existing routes matching those specified in the passed array
2216 * as being weak, meaning that they are ignored for the purpose of
2217 * power decisions. The main intended use case is for sidetone paths
2218 * which couple audio between other independent paths if they are both
2219 * active in order to make the combination work better at the user
2220 * level but which aren't intended to be "used".
2222 * Note that CODEC drivers should not use this as sidetone type paths
2223 * can frequently also be used as bypass paths.
2225 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2226 const struct snd_soc_dapm_route
*route
, int num
)
2231 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2232 for (i
= 0; i
< num
; i
++) {
2233 err
= snd_soc_dapm_weak_route(dapm
, route
);
2238 mutex_unlock(&dapm
->card
->dapm_mutex
);
2242 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2245 * snd_soc_dapm_new_widgets - add new dapm widgets
2246 * @dapm: DAPM context
2248 * Checks the codec for any new dapm widgets and creates them if found.
2250 * Returns 0 for success.
2252 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
2254 struct snd_soc_dapm_widget
*w
;
2257 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2259 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2264 if (w
->num_kcontrols
) {
2265 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2266 sizeof(struct snd_kcontrol
*),
2268 if (!w
->kcontrols
) {
2269 mutex_unlock(&dapm
->card
->dapm_mutex
);
2275 case snd_soc_dapm_switch
:
2276 case snd_soc_dapm_mixer
:
2277 case snd_soc_dapm_mixer_named_ctl
:
2280 case snd_soc_dapm_mux
:
2281 case snd_soc_dapm_virt_mux
:
2282 case snd_soc_dapm_value_mux
:
2285 case snd_soc_dapm_pga
:
2286 case snd_soc_dapm_out_drv
:
2293 /* Read the initial power state from the device */
2295 val
= soc_widget_read(w
, w
->reg
);
2296 val
&= 1 << w
->shift
;
2306 dapm_mark_dirty(w
, "new widget");
2307 dapm_debugfs_add_widget(w
);
2310 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2311 mutex_unlock(&dapm
->card
->dapm_mutex
);
2314 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2317 * snd_soc_dapm_get_volsw - dapm mixer get callback
2318 * @kcontrol: mixer control
2319 * @ucontrol: control element information
2321 * Callback to get the value of a dapm mixer control.
2323 * Returns 0 for success.
2325 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2326 struct snd_ctl_elem_value
*ucontrol
)
2328 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2329 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2330 struct soc_mixer_control
*mc
=
2331 (struct soc_mixer_control
*)kcontrol
->private_value
;
2332 unsigned int reg
= mc
->reg
;
2333 unsigned int shift
= mc
->shift
;
2334 unsigned int rshift
= mc
->rshift
;
2336 unsigned int invert
= mc
->invert
;
2337 unsigned int mask
= (1 << fls(max
)) - 1;
2339 ucontrol
->value
.integer
.value
[0] =
2340 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2341 if (shift
!= rshift
)
2342 ucontrol
->value
.integer
.value
[1] =
2343 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
2345 ucontrol
->value
.integer
.value
[0] =
2346 max
- ucontrol
->value
.integer
.value
[0];
2347 if (shift
!= rshift
)
2348 ucontrol
->value
.integer
.value
[1] =
2349 max
- ucontrol
->value
.integer
.value
[1];
2354 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2357 * snd_soc_dapm_put_volsw - dapm mixer set callback
2358 * @kcontrol: mixer control
2359 * @ucontrol: control element information
2361 * Callback to set the value of a dapm mixer control.
2363 * Returns 0 for success.
2365 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2366 struct snd_ctl_elem_value
*ucontrol
)
2368 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2369 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2370 struct snd_soc_codec
*codec
= widget
->codec
;
2371 struct snd_soc_card
*card
= codec
->card
;
2372 struct soc_mixer_control
*mc
=
2373 (struct soc_mixer_control
*)kcontrol
->private_value
;
2374 unsigned int reg
= mc
->reg
;
2375 unsigned int shift
= mc
->shift
;
2377 unsigned int mask
= (1 << fls(max
)) - 1;
2378 unsigned int invert
= mc
->invert
;
2380 int connect
, change
;
2381 struct snd_soc_dapm_update update
;
2384 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2388 mask
= mask
<< shift
;
2392 /* new connection */
2393 connect
= invert
? 0 : 1;
2395 /* old connection must be powered down */
2396 connect
= invert
? 1 : 0;
2398 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2400 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2402 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2403 widget
= wlist
->widgets
[wi
];
2405 widget
->value
= val
;
2407 update
.kcontrol
= kcontrol
;
2408 update
.widget
= widget
;
2412 widget
->dapm
->update
= &update
;
2414 soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2416 widget
->dapm
->update
= NULL
;
2420 mutex_unlock(&card
->dapm_mutex
);
2423 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2426 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2427 * @kcontrol: mixer control
2428 * @ucontrol: control element information
2430 * Callback to get the value of a dapm enumerated double mixer control.
2432 * Returns 0 for success.
2434 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2435 struct snd_ctl_elem_value
*ucontrol
)
2437 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2438 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2439 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2440 unsigned int val
, bitmask
;
2442 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2444 val
= snd_soc_read(widget
->codec
, e
->reg
);
2445 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2446 if (e
->shift_l
!= e
->shift_r
)
2447 ucontrol
->value
.enumerated
.item
[1] =
2448 (val
>> e
->shift_r
) & (bitmask
- 1);
2452 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2455 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2456 * @kcontrol: mixer control
2457 * @ucontrol: control element information
2459 * Callback to set the value of a dapm enumerated double mixer control.
2461 * Returns 0 for success.
2463 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2464 struct snd_ctl_elem_value
*ucontrol
)
2466 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2467 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2468 struct snd_soc_codec
*codec
= widget
->codec
;
2469 struct snd_soc_card
*card
= codec
->card
;
2470 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2471 unsigned int val
, mux
, change
;
2472 unsigned int mask
, bitmask
;
2473 struct snd_soc_dapm_update update
;
2476 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2478 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2480 mux
= ucontrol
->value
.enumerated
.item
[0];
2481 val
= mux
<< e
->shift_l
;
2482 mask
= (bitmask
- 1) << e
->shift_l
;
2483 if (e
->shift_l
!= e
->shift_r
) {
2484 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2486 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2487 mask
|= (bitmask
- 1) << e
->shift_r
;
2490 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2492 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2494 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2495 widget
= wlist
->widgets
[wi
];
2497 widget
->value
= val
;
2499 update
.kcontrol
= kcontrol
;
2500 update
.widget
= widget
;
2501 update
.reg
= e
->reg
;
2504 widget
->dapm
->update
= &update
;
2506 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2508 widget
->dapm
->update
= NULL
;
2512 mutex_unlock(&card
->dapm_mutex
);
2515 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2518 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2519 * @kcontrol: mixer control
2520 * @ucontrol: control element information
2522 * Returns 0 for success.
2524 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2525 struct snd_ctl_elem_value
*ucontrol
)
2527 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2528 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2530 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2534 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2537 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2538 * @kcontrol: mixer control
2539 * @ucontrol: control element information
2541 * Returns 0 for success.
2543 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2544 struct snd_ctl_elem_value
*ucontrol
)
2546 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2547 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2548 struct snd_soc_codec
*codec
= widget
->codec
;
2549 struct snd_soc_card
*card
= codec
->card
;
2550 struct soc_enum
*e
=
2551 (struct soc_enum
*)kcontrol
->private_value
;
2556 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2559 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2561 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2563 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2564 widget
= wlist
->widgets
[wi
];
2566 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2568 soc_dapm_mux_update_power(widget
, kcontrol
, widget
->value
, e
);
2572 mutex_unlock(&card
->dapm_mutex
);
2575 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2578 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2580 * @kcontrol: mixer control
2581 * @ucontrol: control element information
2583 * Callback to get the value of a dapm semi enumerated double mixer control.
2585 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2586 * used for handling bitfield coded enumeration for example.
2588 * Returns 0 for success.
2590 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2591 struct snd_ctl_elem_value
*ucontrol
)
2593 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2594 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2595 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2596 unsigned int reg_val
, val
, mux
;
2598 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2599 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2600 for (mux
= 0; mux
< e
->max
; mux
++) {
2601 if (val
== e
->values
[mux
])
2604 ucontrol
->value
.enumerated
.item
[0] = mux
;
2605 if (e
->shift_l
!= e
->shift_r
) {
2606 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2607 for (mux
= 0; mux
< e
->max
; mux
++) {
2608 if (val
== e
->values
[mux
])
2611 ucontrol
->value
.enumerated
.item
[1] = mux
;
2616 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2619 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2621 * @kcontrol: mixer control
2622 * @ucontrol: control element information
2624 * Callback to set the value of a dapm semi enumerated double mixer control.
2626 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2627 * used for handling bitfield coded enumeration for example.
2629 * Returns 0 for success.
2631 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2632 struct snd_ctl_elem_value
*ucontrol
)
2634 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2635 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2636 struct snd_soc_codec
*codec
= widget
->codec
;
2637 struct snd_soc_card
*card
= codec
->card
;
2638 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2639 unsigned int val
, mux
, change
;
2641 struct snd_soc_dapm_update update
;
2644 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2646 mux
= ucontrol
->value
.enumerated
.item
[0];
2647 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2648 mask
= e
->mask
<< e
->shift_l
;
2649 if (e
->shift_l
!= e
->shift_r
) {
2650 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2652 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2653 mask
|= e
->mask
<< e
->shift_r
;
2656 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2658 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2660 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2661 widget
= wlist
->widgets
[wi
];
2663 widget
->value
= val
;
2665 update
.kcontrol
= kcontrol
;
2666 update
.widget
= widget
;
2667 update
.reg
= e
->reg
;
2670 widget
->dapm
->update
= &update
;
2672 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2674 widget
->dapm
->update
= NULL
;
2678 mutex_unlock(&card
->dapm_mutex
);
2681 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2684 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2686 * @kcontrol: mixer control
2687 * @uinfo: control element information
2689 * Callback to provide information about a pin switch control.
2691 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2692 struct snd_ctl_elem_info
*uinfo
)
2694 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2696 uinfo
->value
.integer
.min
= 0;
2697 uinfo
->value
.integer
.max
= 1;
2701 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2704 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2706 * @kcontrol: mixer control
2709 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2710 struct snd_ctl_elem_value
*ucontrol
)
2712 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2713 const char *pin
= (const char *)kcontrol
->private_value
;
2715 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2717 ucontrol
->value
.integer
.value
[0] =
2718 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
2720 mutex_unlock(&card
->dapm_mutex
);
2724 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2727 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2729 * @kcontrol: mixer control
2732 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2733 struct snd_ctl_elem_value
*ucontrol
)
2735 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2736 const char *pin
= (const char *)kcontrol
->private_value
;
2738 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2740 if (ucontrol
->value
.integer
.value
[0])
2741 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
2743 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
2745 mutex_unlock(&card
->dapm_mutex
);
2747 snd_soc_dapm_sync(&card
->dapm
);
2750 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2752 static struct snd_soc_dapm_widget
*
2753 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2754 const struct snd_soc_dapm_widget
*widget
)
2756 struct snd_soc_dapm_widget
*w
;
2760 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2764 case snd_soc_dapm_regulator_supply
:
2765 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
2766 if (IS_ERR(w
->regulator
)) {
2767 ret
= PTR_ERR(w
->regulator
);
2768 dev_err(dapm
->dev
, "Failed to request %s: %d\n",
2777 name_len
= strlen(widget
->name
) + 1;
2778 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2779 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2780 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2781 if (w
->name
== NULL
) {
2785 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2786 snprintf((char *)w
->name
, name_len
, "%s %s",
2787 dapm
->codec
->name_prefix
, widget
->name
);
2789 snprintf((char *)w
->name
, name_len
, "%s", widget
->name
);
2792 case snd_soc_dapm_switch
:
2793 case snd_soc_dapm_mixer
:
2794 case snd_soc_dapm_mixer_named_ctl
:
2795 w
->power_check
= dapm_generic_check_power
;
2797 case snd_soc_dapm_mux
:
2798 case snd_soc_dapm_virt_mux
:
2799 case snd_soc_dapm_value_mux
:
2800 w
->power_check
= dapm_generic_check_power
;
2802 case snd_soc_dapm_adc
:
2803 case snd_soc_dapm_aif_out
:
2804 w
->power_check
= dapm_adc_check_power
;
2806 case snd_soc_dapm_dac
:
2807 case snd_soc_dapm_aif_in
:
2808 w
->power_check
= dapm_dac_check_power
;
2810 case snd_soc_dapm_pga
:
2811 case snd_soc_dapm_out_drv
:
2812 case snd_soc_dapm_input
:
2813 case snd_soc_dapm_output
:
2814 case snd_soc_dapm_micbias
:
2815 case snd_soc_dapm_spk
:
2816 case snd_soc_dapm_hp
:
2817 case snd_soc_dapm_mic
:
2818 case snd_soc_dapm_line
:
2819 w
->power_check
= dapm_generic_check_power
;
2821 case snd_soc_dapm_supply
:
2822 case snd_soc_dapm_regulator_supply
:
2823 w
->power_check
= dapm_supply_check_power
;
2825 case snd_soc_dapm_dai
:
2826 w
->power_check
= dapm_dai_check_power
;
2829 w
->power_check
= dapm_always_on_check_power
;
2835 w
->codec
= dapm
->codec
;
2836 w
->platform
= dapm
->platform
;
2837 INIT_LIST_HEAD(&w
->sources
);
2838 INIT_LIST_HEAD(&w
->sinks
);
2839 INIT_LIST_HEAD(&w
->list
);
2840 INIT_LIST_HEAD(&w
->dirty
);
2841 list_add(&w
->list
, &dapm
->card
->widgets
);
2843 /* machine layer set ups unconnected pins and insertions */
2849 * snd_soc_dapm_new_controls - create new dapm controls
2850 * @dapm: DAPM context
2851 * @widget: widget array
2852 * @num: number of widgets
2854 * Creates new DAPM controls based upon the templates.
2856 * Returns 0 for success else error.
2858 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2859 const struct snd_soc_dapm_widget
*widget
,
2862 struct snd_soc_dapm_widget
*w
;
2865 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2866 for (i
= 0; i
< num
; i
++) {
2867 w
= snd_soc_dapm_new_control(dapm
, widget
);
2870 "ASoC: Failed to create DAPM control %s\n",
2876 mutex_unlock(&dapm
->card
->dapm_mutex
);
2879 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2881 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
2882 struct snd_soc_dai
*dai
)
2884 struct snd_soc_dapm_widget
template;
2885 struct snd_soc_dapm_widget
*w
;
2887 WARN_ON(dapm
->dev
!= dai
->dev
);
2889 memset(&template, 0, sizeof(template));
2890 template.reg
= SND_SOC_NOPM
;
2892 if (dai
->driver
->playback
.stream_name
) {
2893 template.id
= snd_soc_dapm_dai
;
2894 template.name
= dai
->driver
->playback
.stream_name
;
2895 template.sname
= dai
->driver
->playback
.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
->playback
.stream_name
);
2907 dai
->playback_widget
= w
;
2910 if (dai
->driver
->capture
.stream_name
) {
2911 template.id
= snd_soc_dapm_dai
;
2912 template.name
= dai
->driver
->capture
.stream_name
;
2913 template.sname
= dai
->driver
->capture
.stream_name
;
2915 dev_dbg(dai
->dev
, "adding %s widget\n",
2918 w
= snd_soc_dapm_new_control(dapm
, &template);
2920 dev_err(dapm
->dev
, "Failed to create %s widget\n",
2921 dai
->driver
->capture
.stream_name
);
2925 dai
->capture_widget
= w
;
2931 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
2933 struct snd_soc_dapm_widget
*dai_w
, *w
;
2934 struct snd_soc_dai
*dai
;
2935 struct snd_soc_dapm_route r
;
2937 memset(&r
, 0, sizeof(r
));
2939 /* For each DAI widget... */
2940 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
2941 if (dai_w
->id
!= snd_soc_dapm_dai
)
2946 /* ...find all widgets with the same stream and link them */
2947 list_for_each_entry(w
, &card
->widgets
, list
) {
2948 if (w
->dapm
!= dai_w
->dapm
)
2951 if (w
->id
== snd_soc_dapm_dai
)
2957 if (dai
->driver
->playback
.stream_name
&&
2959 dai
->driver
->playback
.stream_name
)) {
2960 r
.source
= dai
->playback_widget
->name
;
2962 dev_dbg(dai
->dev
, "%s -> %s\n",
2965 snd_soc_dapm_add_route(w
->dapm
, &r
);
2968 if (dai
->driver
->capture
.stream_name
&&
2970 dai
->driver
->capture
.stream_name
)) {
2972 r
.sink
= dai
->capture_widget
->name
;
2973 dev_dbg(dai
->dev
, "%s -> %s\n",
2976 snd_soc_dapm_add_route(w
->dapm
, &r
);
2984 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
2988 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
2989 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
2990 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
2992 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
2993 w_cpu
= cpu_dai
->playback_widget
;
2994 w_codec
= codec_dai
->playback_widget
;
2996 w_cpu
= cpu_dai
->capture_widget
;
2997 w_codec
= codec_dai
->capture_widget
;
3002 dapm_mark_dirty(w_cpu
, "stream event");
3005 case SND_SOC_DAPM_STREAM_START
:
3008 case SND_SOC_DAPM_STREAM_STOP
:
3011 case SND_SOC_DAPM_STREAM_SUSPEND
:
3012 case SND_SOC_DAPM_STREAM_RESUME
:
3013 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3014 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3021 dapm_mark_dirty(w_codec
, "stream event");
3024 case SND_SOC_DAPM_STREAM_START
:
3025 w_codec
->active
= 1;
3027 case SND_SOC_DAPM_STREAM_STOP
:
3028 w_codec
->active
= 0;
3030 case SND_SOC_DAPM_STREAM_SUSPEND
:
3031 case SND_SOC_DAPM_STREAM_RESUME
:
3032 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3033 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3038 dapm_power_widgets(&rtd
->card
->dapm
, event
);
3042 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3043 * @rtd: PCM runtime data
3044 * @stream: stream name
3045 * @event: stream event
3047 * Sends a stream event to the dapm core. The core then makes any
3048 * necessary widget power changes.
3050 * Returns 0 for success else error.
3052 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3055 struct snd_soc_card
*card
= rtd
->card
;
3057 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3058 soc_dapm_stream_event(rtd
, stream
, event
);
3059 mutex_unlock(&card
->dapm_mutex
);
3063 * snd_soc_dapm_enable_pin - enable pin.
3064 * @dapm: DAPM context
3067 * Enables input/output pin and its parents or children widgets iff there is
3068 * a valid audio route and active audio stream.
3069 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3070 * do any widget power switching.
3072 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3074 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3076 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3079 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3080 * @dapm: DAPM context
3083 * Enables input/output pin regardless of any other state. This is
3084 * intended for use with microphone bias supplies used in microphone
3087 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3088 * do any widget power switching.
3090 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3093 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3096 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3100 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
3103 dapm_mark_dirty(w
, "force enable");
3107 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3110 * snd_soc_dapm_disable_pin - disable pin.
3111 * @dapm: DAPM context
3114 * Disables input/output pin and its parents or children widgets.
3115 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3116 * do any widget power switching.
3118 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3121 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3123 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3126 * snd_soc_dapm_nc_pin - permanently disable pin.
3127 * @dapm: DAPM context
3130 * Marks the specified pin as being not connected, disabling it along
3131 * any parent or child widgets. At present this is identical to
3132 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3133 * additional things such as disabling controls which only affect
3134 * paths through the pin.
3136 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3137 * do any widget power switching.
3139 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3141 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3143 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3146 * snd_soc_dapm_get_pin_status - get audio pin status
3147 * @dapm: DAPM context
3148 * @pin: audio signal pin endpoint (or start point)
3150 * Get audio pin status - connected or disconnected.
3152 * Returns 1 for connected otherwise 0.
3154 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3157 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3160 return w
->connected
;
3164 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
3167 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3168 * @dapm: DAPM context
3169 * @pin: audio signal pin endpoint (or start point)
3171 * Mark the given endpoint or pin as ignoring suspend. When the
3172 * system is disabled a path between two endpoints flagged as ignoring
3173 * suspend will not be disabled. The path must already be enabled via
3174 * normal means at suspend time, it will not be turned on if it was not
3177 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
3180 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
3183 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3187 w
->ignore_suspend
= 1;
3191 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
3193 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
3194 struct snd_soc_dapm_widget
*w
)
3196 struct snd_soc_dapm_path
*p
;
3198 list_for_each_entry(p
, &card
->paths
, list
) {
3199 if ((p
->source
== w
) || (p
->sink
== w
)) {
3201 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3202 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
3203 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
3205 /* Connected to something other than the codec */
3206 if (p
->source
->dapm
!= p
->sink
->dapm
)
3209 * Loopback connection from codec external pin to
3210 * codec external pin
3212 if (p
->sink
->id
== snd_soc_dapm_input
) {
3213 switch (p
->source
->id
) {
3214 case snd_soc_dapm_output
:
3215 case snd_soc_dapm_micbias
:
3228 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3229 * @codec: The codec whose pins should be processed
3231 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3232 * which are unused. Pins are used if they are connected externally to the
3233 * codec, whether that be to some other device, or a loop-back connection to
3236 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
3238 struct snd_soc_card
*card
= codec
->card
;
3239 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3240 struct snd_soc_dapm_widget
*w
;
3242 dev_dbg(codec
->dev
, "Auto NC: DAPMs: card:%p codec:%p\n",
3243 &card
->dapm
, &codec
->dapm
);
3245 list_for_each_entry(w
, &card
->widgets
, list
) {
3246 if (w
->dapm
!= dapm
)
3249 case snd_soc_dapm_input
:
3250 case snd_soc_dapm_output
:
3251 case snd_soc_dapm_micbias
:
3252 dev_dbg(codec
->dev
, "Auto NC: Checking widget %s\n",
3254 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
3256 "... Not in map; disabling\n");
3257 snd_soc_dapm_nc_pin(dapm
, w
->name
);
3267 * snd_soc_dapm_free - free dapm resources
3268 * @dapm: DAPM context
3270 * Free all dapm widgets and resources.
3272 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
3274 snd_soc_dapm_sys_remove(dapm
->dev
);
3275 dapm_debugfs_cleanup(dapm
);
3276 dapm_free_widgets(dapm
);
3277 list_del(&dapm
->list
);
3279 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
3281 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
3283 struct snd_soc_dapm_widget
*w
;
3284 LIST_HEAD(down_list
);
3287 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
3288 if (w
->dapm
!= dapm
)
3291 dapm_seq_insert(w
, &down_list
, false);
3297 /* If there were no widgets to power down we're already in
3301 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
3302 snd_soc_dapm_set_bias_level(dapm
,
3303 SND_SOC_BIAS_PREPARE
);
3304 dapm_seq_run(dapm
, &down_list
, 0, false);
3305 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
3306 snd_soc_dapm_set_bias_level(dapm
,
3307 SND_SOC_BIAS_STANDBY
);
3312 * snd_soc_dapm_shutdown - callback for system shutdown
3314 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
3316 struct snd_soc_codec
*codec
;
3318 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
3319 soc_dapm_shutdown_codec(&codec
->dapm
);
3320 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
3321 snd_soc_dapm_set_bias_level(&codec
->dapm
,
3326 /* Module information */
3327 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3328 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3329 MODULE_LICENSE("GPL");