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/clk.h>
39 #include <linux/slab.h>
40 #include <sound/core.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc.h>
44 #include <sound/initval.h>
46 #include <trace/events/asoc.h>
48 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
50 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
51 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
53 int (*connected
)(struct snd_soc_dapm_widget
*source
,
54 struct snd_soc_dapm_widget
*sink
));
55 static struct snd_soc_dapm_widget
*
56 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
57 const struct snd_soc_dapm_widget
*widget
);
59 /* dapm power sequences - make this per codec in the future */
60 static int dapm_up_seq
[] = {
61 [snd_soc_dapm_pre
] = 0,
62 [snd_soc_dapm_regulator_supply
] = 1,
63 [snd_soc_dapm_clock_supply
] = 1,
64 [snd_soc_dapm_supply
] = 2,
65 [snd_soc_dapm_micbias
] = 3,
66 [snd_soc_dapm_dai_link
] = 2,
67 [snd_soc_dapm_dai_in
] = 4,
68 [snd_soc_dapm_dai_out
] = 4,
69 [snd_soc_dapm_aif_in
] = 4,
70 [snd_soc_dapm_aif_out
] = 4,
71 [snd_soc_dapm_mic
] = 5,
72 [snd_soc_dapm_mux
] = 6,
73 [snd_soc_dapm_virt_mux
] = 6,
74 [snd_soc_dapm_value_mux
] = 6,
75 [snd_soc_dapm_dac
] = 7,
76 [snd_soc_dapm_switch
] = 8,
77 [snd_soc_dapm_mixer
] = 8,
78 [snd_soc_dapm_mixer_named_ctl
] = 8,
79 [snd_soc_dapm_pga
] = 9,
80 [snd_soc_dapm_adc
] = 10,
81 [snd_soc_dapm_out_drv
] = 11,
82 [snd_soc_dapm_hp
] = 11,
83 [snd_soc_dapm_spk
] = 11,
84 [snd_soc_dapm_line
] = 11,
85 [snd_soc_dapm_kcontrol
] = 12,
86 [snd_soc_dapm_post
] = 13,
89 static int dapm_down_seq
[] = {
90 [snd_soc_dapm_pre
] = 0,
91 [snd_soc_dapm_kcontrol
] = 1,
92 [snd_soc_dapm_adc
] = 2,
93 [snd_soc_dapm_hp
] = 3,
94 [snd_soc_dapm_spk
] = 3,
95 [snd_soc_dapm_line
] = 3,
96 [snd_soc_dapm_out_drv
] = 3,
97 [snd_soc_dapm_pga
] = 4,
98 [snd_soc_dapm_switch
] = 5,
99 [snd_soc_dapm_mixer_named_ctl
] = 5,
100 [snd_soc_dapm_mixer
] = 5,
101 [snd_soc_dapm_dac
] = 6,
102 [snd_soc_dapm_mic
] = 7,
103 [snd_soc_dapm_micbias
] = 8,
104 [snd_soc_dapm_mux
] = 9,
105 [snd_soc_dapm_virt_mux
] = 9,
106 [snd_soc_dapm_value_mux
] = 9,
107 [snd_soc_dapm_aif_in
] = 10,
108 [snd_soc_dapm_aif_out
] = 10,
109 [snd_soc_dapm_dai_in
] = 10,
110 [snd_soc_dapm_dai_out
] = 10,
111 [snd_soc_dapm_dai_link
] = 11,
112 [snd_soc_dapm_supply
] = 12,
113 [snd_soc_dapm_clock_supply
] = 13,
114 [snd_soc_dapm_regulator_supply
] = 13,
115 [snd_soc_dapm_post
] = 14,
118 static void pop_wait(u32 pop_time
)
121 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
124 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
132 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
137 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
138 dev_info(dev
, "%s", buf
);
144 static bool dapm_dirty_widget(struct snd_soc_dapm_widget
*w
)
146 return !list_empty(&w
->dirty
);
149 static void dapm_mark_dirty(struct snd_soc_dapm_widget
*w
, const char *reason
)
151 if (!dapm_dirty_widget(w
)) {
152 dev_vdbg(w
->dapm
->dev
, "Marking %s dirty due to %s\n",
154 list_add_tail(&w
->dirty
, &w
->dapm
->card
->dapm_dirty
);
158 void dapm_mark_io_dirty(struct snd_soc_dapm_context
*dapm
)
160 struct snd_soc_card
*card
= dapm
->card
;
161 struct snd_soc_dapm_widget
*w
;
163 mutex_lock(&card
->dapm_mutex
);
165 list_for_each_entry(w
, &card
->widgets
, list
) {
167 case snd_soc_dapm_input
:
168 case snd_soc_dapm_output
:
169 dapm_mark_dirty(w
, "Rechecking inputs and outputs");
176 mutex_unlock(&card
->dapm_mutex
);
178 EXPORT_SYMBOL_GPL(dapm_mark_io_dirty
);
180 /* create a new dapm widget */
181 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
182 const struct snd_soc_dapm_widget
*_widget
)
184 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
187 struct dapm_kcontrol_data
{
189 struct snd_soc_dapm_widget
*widget
;
190 struct list_head paths
;
191 struct snd_soc_dapm_widget_list
*wlist
;
194 static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget
*widget
,
195 struct snd_kcontrol
*kcontrol
)
197 struct dapm_kcontrol_data
*data
;
198 struct soc_mixer_control
*mc
;
200 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
202 dev_err(widget
->dapm
->dev
,
203 "ASoC: can't allocate kcontrol data for %s\n",
208 INIT_LIST_HEAD(&data
->paths
);
210 switch (widget
->id
) {
211 case snd_soc_dapm_switch
:
212 case snd_soc_dapm_mixer
:
213 case snd_soc_dapm_mixer_named_ctl
:
214 mc
= (struct soc_mixer_control
*)kcontrol
->private_value
;
216 if (mc
->autodisable
) {
217 struct snd_soc_dapm_widget
template;
219 memset(&template, 0, sizeof(template));
220 template.reg
= mc
->reg
;
221 template.mask
= (1 << fls(mc
->max
)) - 1;
222 template.shift
= mc
->shift
;
224 template.off_val
= mc
->max
;
226 template.off_val
= 0;
227 template.on_val
= template.off_val
;
228 template.id
= snd_soc_dapm_kcontrol
;
229 template.name
= kcontrol
->id
.name
;
231 data
->value
= template.on_val
;
233 data
->widget
= snd_soc_dapm_new_control(widget
->dapm
,
245 kcontrol
->private_data
= data
;
250 static void dapm_kcontrol_free(struct snd_kcontrol
*kctl
)
252 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kctl
);
258 static struct snd_soc_dapm_widget_list
*dapm_kcontrol_get_wlist(
259 const struct snd_kcontrol
*kcontrol
)
261 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
266 static int dapm_kcontrol_add_widget(struct snd_kcontrol
*kcontrol
,
267 struct snd_soc_dapm_widget
*widget
)
269 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
270 struct snd_soc_dapm_widget_list
*new_wlist
;
274 n
= data
->wlist
->num_widgets
+ 1;
278 new_wlist
= krealloc(data
->wlist
,
279 sizeof(*new_wlist
) + sizeof(widget
) * n
, GFP_KERNEL
);
283 new_wlist
->widgets
[n
- 1] = widget
;
284 new_wlist
->num_widgets
= n
;
286 data
->wlist
= new_wlist
;
291 static void dapm_kcontrol_add_path(const struct snd_kcontrol
*kcontrol
,
292 struct snd_soc_dapm_path
*path
)
294 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
296 list_add_tail(&path
->list_kcontrol
, &data
->paths
);
299 snd_soc_dapm_add_path(data
->widget
->dapm
, data
->widget
,
300 path
->source
, NULL
, NULL
);
304 static bool dapm_kcontrol_is_powered(const struct snd_kcontrol
*kcontrol
)
306 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
311 return data
->widget
->power
;
314 static struct list_head
*dapm_kcontrol_get_path_list(
315 const struct snd_kcontrol
*kcontrol
)
317 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
322 #define dapm_kcontrol_for_each_path(path, kcontrol) \
323 list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
326 static unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol
*kcontrol
)
328 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
333 static bool dapm_kcontrol_set_value(const struct snd_kcontrol
*kcontrol
,
336 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
338 if (data
->value
== value
)
342 data
->widget
->on_val
= value
;
350 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
351 * @kcontrol: The kcontrol
353 struct snd_soc_codec
*snd_soc_dapm_kcontrol_codec(struct snd_kcontrol
*kcontrol
)
355 return dapm_kcontrol_get_wlist(kcontrol
)->widgets
[0]->codec
;
357 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_codec
);
359 static void dapm_reset(struct snd_soc_card
*card
)
361 struct snd_soc_dapm_widget
*w
;
363 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
365 list_for_each_entry(w
, &card
->widgets
, list
) {
366 w
->new_power
= w
->power
;
367 w
->power_checked
= false;
373 static int soc_widget_read(struct snd_soc_dapm_widget
*w
, int reg
,
377 *value
= snd_soc_read(w
->codec
, reg
);
379 } else if (w
->platform
) {
380 *value
= snd_soc_platform_read(w
->platform
, reg
);
384 dev_err(w
->dapm
->dev
, "ASoC: no valid widget read method\n");
388 static int soc_widget_write(struct snd_soc_dapm_widget
*w
, int reg
,
392 return snd_soc_write(w
->codec
, reg
, val
);
393 else if (w
->platform
)
394 return snd_soc_platform_write(w
->platform
, reg
, val
);
396 dev_err(w
->dapm
->dev
, "ASoC: no valid widget write method\n");
400 static inline void soc_widget_lock(struct snd_soc_dapm_widget
*w
)
402 if (w
->codec
&& !w
->codec
->using_regmap
)
403 mutex_lock(&w
->codec
->mutex
);
404 else if (w
->platform
)
405 mutex_lock(&w
->platform
->mutex
);
408 static inline void soc_widget_unlock(struct snd_soc_dapm_widget
*w
)
410 if (w
->codec
&& !w
->codec
->using_regmap
)
411 mutex_unlock(&w
->codec
->mutex
);
412 else if (w
->platform
)
413 mutex_unlock(&w
->platform
->mutex
);
416 static void soc_dapm_async_complete(struct snd_soc_dapm_context
*dapm
)
418 if (dapm
->codec
&& dapm
->codec
->using_regmap
)
419 regmap_async_complete(dapm
->codec
->control_data
);
422 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget
*w
,
423 unsigned short reg
, unsigned int mask
, unsigned int value
)
426 unsigned int old
, new;
429 if (w
->codec
&& w
->codec
->using_regmap
) {
430 ret
= regmap_update_bits_check_async(w
->codec
->control_data
,
437 ret
= soc_widget_read(w
, reg
, &old
);
439 soc_widget_unlock(w
);
443 new = (old
& ~mask
) | (value
& mask
);
446 ret
= soc_widget_write(w
, reg
, new);
448 soc_widget_unlock(w
);
452 soc_widget_unlock(w
);
459 * snd_soc_dapm_set_bias_level - set the bias level for the system
460 * @dapm: DAPM context
461 * @level: level to configure
463 * Configure the bias (power) levels for the SoC audio device.
465 * Returns 0 for success else error.
467 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
468 enum snd_soc_bias_level level
)
470 struct snd_soc_card
*card
= dapm
->card
;
473 trace_snd_soc_bias_level_start(card
, level
);
475 if (card
&& card
->set_bias_level
)
476 ret
= card
->set_bias_level(card
, dapm
, level
);
481 if (dapm
->codec
->driver
->set_bias_level
)
482 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
485 dapm
->bias_level
= level
;
486 } else if (!card
|| dapm
!= &card
->dapm
) {
487 dapm
->bias_level
= level
;
493 if (card
&& card
->set_bias_level_post
)
494 ret
= card
->set_bias_level_post(card
, dapm
, level
);
496 trace_snd_soc_bias_level_done(card
, level
);
501 /* set up initial codec paths */
502 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
503 struct snd_soc_dapm_path
*p
, int i
)
506 case snd_soc_dapm_switch
:
507 case snd_soc_dapm_mixer
:
508 case snd_soc_dapm_mixer_named_ctl
: {
510 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
511 w
->kcontrol_news
[i
].private_value
;
513 unsigned int shift
= mc
->shift
;
515 unsigned int mask
= (1 << fls(max
)) - 1;
516 unsigned int invert
= mc
->invert
;
518 if (reg
!= SND_SOC_NOPM
) {
519 soc_widget_read(w
, reg
, &val
);
520 val
= (val
>> shift
) & mask
;
530 case snd_soc_dapm_mux
: {
531 struct soc_enum
*e
= (struct soc_enum
*)
532 w
->kcontrol_news
[i
].private_value
;
533 unsigned int val
, item
;
535 soc_widget_read(w
, e
->reg
, &val
);
536 item
= (val
>> e
->shift_l
) & e
->mask
;
538 if (item
< e
->max
&& !strcmp(p
->name
, e
->texts
[item
]))
544 case snd_soc_dapm_virt_mux
: {
545 struct soc_enum
*e
= (struct soc_enum
*)
546 w
->kcontrol_news
[i
].private_value
;
549 /* since a virtual mux has no backing registers to
550 * decide which path to connect, it will try to match
551 * with the first enumeration. This is to ensure
552 * that the default mux choice (the first) will be
553 * correctly powered up during initialization.
555 if (!strcmp(p
->name
, e
->texts
[0]))
559 case snd_soc_dapm_value_mux
: {
560 struct soc_enum
*e
= (struct soc_enum
*)
561 w
->kcontrol_news
[i
].private_value
;
562 unsigned int val
, item
;
564 soc_widget_read(w
, e
->reg
, &val
);
565 val
= (val
>> e
->shift_l
) & e
->mask
;
566 for (item
= 0; item
< e
->max
; item
++) {
567 if (val
== e
->values
[item
])
571 if (item
< e
->max
&& !strcmp(p
->name
, e
->texts
[item
]))
577 /* does not affect routing - always connected */
578 case snd_soc_dapm_pga
:
579 case snd_soc_dapm_out_drv
:
580 case snd_soc_dapm_output
:
581 case snd_soc_dapm_adc
:
582 case snd_soc_dapm_input
:
583 case snd_soc_dapm_siggen
:
584 case snd_soc_dapm_dac
:
585 case snd_soc_dapm_micbias
:
586 case snd_soc_dapm_vmid
:
587 case snd_soc_dapm_supply
:
588 case snd_soc_dapm_regulator_supply
:
589 case snd_soc_dapm_clock_supply
:
590 case snd_soc_dapm_aif_in
:
591 case snd_soc_dapm_aif_out
:
592 case snd_soc_dapm_dai_in
:
593 case snd_soc_dapm_dai_out
:
594 case snd_soc_dapm_hp
:
595 case snd_soc_dapm_mic
:
596 case snd_soc_dapm_spk
:
597 case snd_soc_dapm_line
:
598 case snd_soc_dapm_dai_link
:
599 case snd_soc_dapm_kcontrol
:
602 /* does affect routing - dynamically connected */
603 case snd_soc_dapm_pre
:
604 case snd_soc_dapm_post
:
610 /* connect mux widget to its interconnecting audio paths */
611 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
612 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
613 struct snd_soc_dapm_path
*path
, const char *control_name
,
614 const struct snd_kcontrol_new
*kcontrol
)
616 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
619 for (i
= 0; i
< e
->max
; i
++) {
620 if (!(strcmp(control_name
, e
->texts
[i
]))) {
621 list_add(&path
->list
, &dapm
->card
->paths
);
622 list_add(&path
->list_sink
, &dest
->sources
);
623 list_add(&path
->list_source
, &src
->sinks
);
624 path
->name
= (char*)e
->texts
[i
];
625 dapm_set_path_status(dest
, path
, 0);
633 /* connect mixer widget to its interconnecting audio paths */
634 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
635 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
636 struct snd_soc_dapm_path
*path
, const char *control_name
)
640 /* search for mixer kcontrol */
641 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
642 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
643 list_add(&path
->list
, &dapm
->card
->paths
);
644 list_add(&path
->list_sink
, &dest
->sources
);
645 list_add(&path
->list_source
, &src
->sinks
);
646 path
->name
= dest
->kcontrol_news
[i
].name
;
647 dapm_set_path_status(dest
, path
, i
);
654 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
655 struct snd_soc_dapm_widget
*kcontrolw
,
656 const struct snd_kcontrol_new
*kcontrol_new
,
657 struct snd_kcontrol
**kcontrol
)
659 struct snd_soc_dapm_widget
*w
;
664 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
665 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
667 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
668 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
670 *kcontrol
= w
->kcontrols
[i
];
680 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
681 * create it. Either way, add the widget into the control's widget list
683 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget
*w
,
686 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
687 struct snd_card
*card
= dapm
->card
->snd_card
;
691 struct snd_kcontrol
*kcontrol
;
692 bool wname_in_long_name
, kcname_in_long_name
;
698 prefix
= dapm
->codec
->name_prefix
;
703 prefix_len
= strlen(prefix
) + 1;
707 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
712 wname_in_long_name
= false;
713 kcname_in_long_name
= true;
716 case snd_soc_dapm_switch
:
717 case snd_soc_dapm_mixer
:
718 wname_in_long_name
= true;
719 kcname_in_long_name
= true;
721 case snd_soc_dapm_mixer_named_ctl
:
722 wname_in_long_name
= false;
723 kcname_in_long_name
= true;
725 case snd_soc_dapm_mux
:
726 case snd_soc_dapm_virt_mux
:
727 case snd_soc_dapm_value_mux
:
728 wname_in_long_name
= true;
729 kcname_in_long_name
= false;
736 if (wname_in_long_name
&& kcname_in_long_name
) {
738 * The control will get a prefix from the control
739 * creation process but we're also using the same
740 * prefix for widgets so cut the prefix off the
741 * front of the widget name.
743 long_name
= kasprintf(GFP_KERNEL
, "%s %s",
744 w
->name
+ prefix_len
,
745 w
->kcontrol_news
[kci
].name
);
746 if (long_name
== NULL
)
750 } else if (wname_in_long_name
) {
752 name
= w
->name
+ prefix_len
;
755 name
= w
->kcontrol_news
[kci
].name
;
758 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], NULL
, name
,
763 kcontrol
->private_free
= dapm_kcontrol_free
;
765 ret
= dapm_kcontrol_data_alloc(w
, kcontrol
);
767 snd_ctl_free_one(kcontrol
);
771 ret
= snd_ctl_add(card
, kcontrol
);
774 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
780 ret
= dapm_kcontrol_add_widget(kcontrol
, w
);
784 w
->kcontrols
[kci
] = kcontrol
;
789 /* create new dapm mixer control */
790 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
793 struct snd_soc_dapm_path
*path
;
796 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
798 list_for_each_entry(path
, &w
->sources
, list_sink
) {
799 /* mixer/mux paths name must match control name */
800 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
803 if (w
->kcontrols
[i
]) {
804 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
808 ret
= dapm_create_or_share_mixmux_kcontrol(w
, i
);
812 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
819 /* create new dapm mux control */
820 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
822 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
823 struct snd_soc_dapm_path
*path
;
826 if (w
->num_kcontrols
!= 1) {
828 "ASoC: mux %s has incorrect number of controls\n",
833 if (list_empty(&w
->sources
)) {
834 dev_err(dapm
->dev
, "ASoC: mux %s has no paths\n", w
->name
);
838 ret
= dapm_create_or_share_mixmux_kcontrol(w
, 0);
842 list_for_each_entry(path
, &w
->sources
, list_sink
)
843 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
848 /* create new dapm volume control */
849 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
851 if (w
->num_kcontrols
)
852 dev_err(w
->dapm
->dev
,
853 "ASoC: PGA controls not supported: '%s'\n", w
->name
);
858 /* reset 'walked' bit for each dapm path */
859 static void dapm_clear_walk_output(struct snd_soc_dapm_context
*dapm
,
860 struct list_head
*sink
)
862 struct snd_soc_dapm_path
*p
;
864 list_for_each_entry(p
, sink
, list_source
) {
867 dapm_clear_walk_output(dapm
, &p
->sink
->sinks
);
872 static void dapm_clear_walk_input(struct snd_soc_dapm_context
*dapm
,
873 struct list_head
*source
)
875 struct snd_soc_dapm_path
*p
;
877 list_for_each_entry(p
, source
, list_sink
) {
880 dapm_clear_walk_input(dapm
, &p
->source
->sources
);
886 /* We implement power down on suspend by checking the power state of
887 * the ALSA card - when we are suspending the ALSA state for the card
890 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
892 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
895 case SNDRV_CTL_POWER_D3hot
:
896 case SNDRV_CTL_POWER_D3cold
:
897 if (widget
->ignore_suspend
)
898 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
900 return widget
->ignore_suspend
;
906 /* add widget to list if it's not already in the list */
907 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
908 struct snd_soc_dapm_widget
*w
)
910 struct snd_soc_dapm_widget_list
*wlist
;
911 int wlistsize
, wlistentries
, i
;
918 /* is this widget already in the list */
919 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
920 if (wlist
->widgets
[i
] == w
)
924 /* allocate some new space */
925 wlistentries
= wlist
->num_widgets
+ 1;
926 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
927 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
928 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
930 dev_err(w
->dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
936 /* insert the widget */
937 dev_dbg(w
->dapm
->dev
, "ASoC: added %s in widget list pos %d\n",
938 w
->name
, wlist
->num_widgets
);
940 wlist
->widgets
[wlist
->num_widgets
] = w
;
941 wlist
->num_widgets
++;
946 * Recursively check for a completed path to an active or physically connected
947 * output widget. Returns number of complete paths.
949 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
950 struct snd_soc_dapm_widget_list
**list
)
952 struct snd_soc_dapm_path
*path
;
955 if (widget
->outputs
>= 0)
956 return widget
->outputs
;
958 DAPM_UPDATE_STAT(widget
, path_checks
);
960 switch (widget
->id
) {
961 case snd_soc_dapm_supply
:
962 case snd_soc_dapm_regulator_supply
:
963 case snd_soc_dapm_clock_supply
:
964 case snd_soc_dapm_kcontrol
:
970 switch (widget
->id
) {
971 case snd_soc_dapm_adc
:
972 case snd_soc_dapm_aif_out
:
973 case snd_soc_dapm_dai_out
:
974 if (widget
->active
) {
975 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
976 return widget
->outputs
;
982 if (widget
->connected
) {
983 /* connected pin ? */
984 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
985 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
986 return widget
->outputs
;
989 /* connected jack or spk ? */
990 if (widget
->id
== snd_soc_dapm_hp
||
991 widget
->id
== snd_soc_dapm_spk
||
992 (widget
->id
== snd_soc_dapm_line
&&
993 !list_empty(&widget
->sources
))) {
994 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
995 return widget
->outputs
;
999 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
1000 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1011 trace_snd_soc_dapm_output_path(widget
, path
);
1013 if (path
->sink
&& path
->connect
) {
1017 /* do we need to add this widget to the list ? */
1020 err
= dapm_list_add_widget(list
, path
->sink
);
1022 dev_err(widget
->dapm
->dev
,
1023 "ASoC: could not add widget %s\n",
1030 con
+= is_connected_output_ep(path
->sink
, list
);
1036 widget
->outputs
= con
;
1042 * Recursively check for a completed path to an active or physically connected
1043 * input widget. Returns number of complete paths.
1045 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
1046 struct snd_soc_dapm_widget_list
**list
)
1048 struct snd_soc_dapm_path
*path
;
1051 if (widget
->inputs
>= 0)
1052 return widget
->inputs
;
1054 DAPM_UPDATE_STAT(widget
, path_checks
);
1056 switch (widget
->id
) {
1057 case snd_soc_dapm_supply
:
1058 case snd_soc_dapm_regulator_supply
:
1059 case snd_soc_dapm_clock_supply
:
1060 case snd_soc_dapm_kcontrol
:
1066 /* active stream ? */
1067 switch (widget
->id
) {
1068 case snd_soc_dapm_dac
:
1069 case snd_soc_dapm_aif_in
:
1070 case snd_soc_dapm_dai_in
:
1071 if (widget
->active
) {
1072 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1073 return widget
->inputs
;
1079 if (widget
->connected
) {
1080 /* connected pin ? */
1081 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
1082 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1083 return widget
->inputs
;
1086 /* connected VMID/Bias for lower pops */
1087 if (widget
->id
== snd_soc_dapm_vmid
) {
1088 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1089 return widget
->inputs
;
1092 /* connected jack ? */
1093 if (widget
->id
== snd_soc_dapm_mic
||
1094 (widget
->id
== snd_soc_dapm_line
&&
1095 !list_empty(&widget
->sinks
))) {
1096 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1097 return widget
->inputs
;
1100 /* signal generator */
1101 if (widget
->id
== snd_soc_dapm_siggen
) {
1102 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1103 return widget
->inputs
;
1107 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
1108 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1119 trace_snd_soc_dapm_input_path(widget
, path
);
1121 if (path
->source
&& path
->connect
) {
1125 /* do we need to add this widget to the list ? */
1128 err
= dapm_list_add_widget(list
, path
->source
);
1130 dev_err(widget
->dapm
->dev
,
1131 "ASoC: could not add widget %s\n",
1138 con
+= is_connected_input_ep(path
->source
, list
);
1144 widget
->inputs
= con
;
1150 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1151 * @dai: the soc DAI.
1152 * @stream: stream direction.
1153 * @list: list of active widgets for this stream.
1155 * Queries DAPM graph as to whether an valid audio stream path exists for
1156 * the initial stream specified by name. This takes into account
1157 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1159 * Returns the number of valid paths or negative error.
1161 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1162 struct snd_soc_dapm_widget_list
**list
)
1164 struct snd_soc_card
*card
= dai
->card
;
1167 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1170 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1171 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
1172 dapm_clear_walk_output(&card
->dapm
,
1173 &dai
->playback_widget
->sinks
);
1175 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
1176 dapm_clear_walk_input(&card
->dapm
,
1177 &dai
->capture_widget
->sources
);
1180 trace_snd_soc_dapm_connected(paths
, stream
);
1181 mutex_unlock(&card
->dapm_mutex
);
1187 * Handler for generic register modifier widget.
1189 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
1190 struct snd_kcontrol
*kcontrol
, int event
)
1194 if (SND_SOC_DAPM_EVENT_ON(event
))
1199 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
1200 w
->mask
<< w
->shift
, val
<< w
->shift
);
1204 EXPORT_SYMBOL_GPL(dapm_reg_event
);
1207 * Handler for regulator supply widget.
1209 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1210 struct snd_kcontrol
*kcontrol
, int event
)
1214 soc_dapm_async_complete(w
->dapm
);
1216 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1217 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1218 ret
= regulator_allow_bypass(w
->regulator
, false);
1220 dev_warn(w
->dapm
->dev
,
1221 "ASoC: Failed to unbypass %s: %d\n",
1225 return regulator_enable(w
->regulator
);
1227 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1228 ret
= regulator_allow_bypass(w
->regulator
, true);
1230 dev_warn(w
->dapm
->dev
,
1231 "ASoC: Failed to bypass %s: %d\n",
1235 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1238 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1241 * Handler for clock supply widget.
1243 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1244 struct snd_kcontrol
*kcontrol
, int event
)
1249 soc_dapm_async_complete(w
->dapm
);
1251 #ifdef CONFIG_HAVE_CLK
1252 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1253 return clk_prepare_enable(w
->clk
);
1255 clk_disable_unprepare(w
->clk
);
1261 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1263 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1265 if (w
->power_checked
)
1266 return w
->new_power
;
1271 w
->new_power
= w
->power_check(w
);
1273 w
->power_checked
= true;
1275 return w
->new_power
;
1278 /* Generic check to see if a widget should be powered.
1280 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1284 DAPM_UPDATE_STAT(w
, power_checks
);
1286 in
= is_connected_input_ep(w
, NULL
);
1287 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1288 out
= is_connected_output_ep(w
, NULL
);
1289 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1290 return out
!= 0 && in
!= 0;
1293 /* Check to see if an ADC has power */
1294 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
1298 DAPM_UPDATE_STAT(w
, power_checks
);
1301 in
= is_connected_input_ep(w
, NULL
);
1302 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1305 return dapm_generic_check_power(w
);
1309 /* Check to see if a DAC has power */
1310 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
1314 DAPM_UPDATE_STAT(w
, power_checks
);
1317 out
= is_connected_output_ep(w
, NULL
);
1318 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1321 return dapm_generic_check_power(w
);
1325 /* Check to see if a power supply is needed */
1326 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1328 struct snd_soc_dapm_path
*path
;
1330 DAPM_UPDATE_STAT(w
, power_checks
);
1332 /* Check if one of our outputs is connected */
1333 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1334 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1339 if (path
->connected
&&
1340 !path
->connected(path
->source
, path
->sink
))
1346 if (dapm_widget_power_check(path
->sink
))
1353 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1358 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1359 struct snd_soc_dapm_widget
*b
,
1367 sort
= dapm_down_seq
;
1369 if (sort
[a
->id
] != sort
[b
->id
])
1370 return sort
[a
->id
] - sort
[b
->id
];
1371 if (a
->subseq
!= b
->subseq
) {
1373 return a
->subseq
- b
->subseq
;
1375 return b
->subseq
- a
->subseq
;
1377 if (a
->reg
!= b
->reg
)
1378 return a
->reg
- b
->reg
;
1379 if (a
->dapm
!= b
->dapm
)
1380 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1385 /* Insert a widget in order into a DAPM power sequence. */
1386 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1387 struct list_head
*list
,
1390 struct snd_soc_dapm_widget
*w
;
1392 list_for_each_entry(w
, list
, power_list
)
1393 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1394 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1398 list_add_tail(&new_widget
->power_list
, list
);
1401 static void dapm_seq_check_event(struct snd_soc_card
*card
,
1402 struct snd_soc_dapm_widget
*w
, int event
)
1404 const char *ev_name
;
1408 case SND_SOC_DAPM_PRE_PMU
:
1409 ev_name
= "PRE_PMU";
1412 case SND_SOC_DAPM_POST_PMU
:
1413 ev_name
= "POST_PMU";
1416 case SND_SOC_DAPM_PRE_PMD
:
1417 ev_name
= "PRE_PMD";
1420 case SND_SOC_DAPM_POST_PMD
:
1421 ev_name
= "POST_PMD";
1424 case SND_SOC_DAPM_WILL_PMU
:
1425 ev_name
= "WILL_PMU";
1428 case SND_SOC_DAPM_WILL_PMD
:
1429 ev_name
= "WILL_PMD";
1433 WARN(1, "Unknown event %d\n", event
);
1437 if (w
->new_power
!= power
)
1440 if (w
->event
&& (w
->event_flags
& event
)) {
1441 pop_dbg(w
->dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1443 soc_dapm_async_complete(w
->dapm
);
1444 trace_snd_soc_dapm_widget_event_start(w
, event
);
1445 ret
= w
->event(w
, NULL
, event
);
1446 trace_snd_soc_dapm_widget_event_done(w
, event
);
1448 dev_err(w
->dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1449 ev_name
, w
->name
, ret
);
1453 /* Apply the coalesced changes from a DAPM sequence */
1454 static void dapm_seq_run_coalesced(struct snd_soc_card
*card
,
1455 struct list_head
*pending
)
1457 struct snd_soc_dapm_widget
*w
;
1459 unsigned int value
= 0;
1460 unsigned int mask
= 0;
1462 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1465 list_for_each_entry(w
, pending
, power_list
) {
1466 WARN_ON(reg
!= w
->reg
);
1467 w
->power
= w
->new_power
;
1469 mask
|= w
->mask
<< w
->shift
;
1471 value
|= w
->on_val
<< w
->shift
;
1473 value
|= w
->off_val
<< w
->shift
;
1475 pop_dbg(w
->dapm
->dev
, card
->pop_time
,
1476 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1477 w
->name
, reg
, value
, mask
);
1479 /* Check for events */
1480 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMU
);
1481 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMD
);
1485 /* Any widget will do, they should all be updating the
1488 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1491 pop_dbg(w
->dapm
->dev
, card
->pop_time
,
1492 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1493 value
, mask
, reg
, card
->pop_time
);
1494 pop_wait(card
->pop_time
);
1495 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1498 list_for_each_entry(w
, pending
, power_list
) {
1499 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMU
);
1500 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMD
);
1504 /* Apply a DAPM power sequence.
1506 * We walk over a pre-sorted list of widgets to apply power to. In
1507 * order to minimise the number of writes to the device required
1508 * multiple widgets will be updated in a single write where possible.
1509 * Currently anything that requires more than a single write is not
1512 static void dapm_seq_run(struct snd_soc_card
*card
,
1513 struct list_head
*list
, int event
, bool power_up
)
1515 struct snd_soc_dapm_widget
*w
, *n
;
1516 struct snd_soc_dapm_context
*d
;
1519 int cur_subseq
= -1;
1520 int cur_reg
= SND_SOC_NOPM
;
1521 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1528 sort
= dapm_down_seq
;
1530 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1533 /* Do we need to apply any queued changes? */
1534 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1535 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1536 if (!list_empty(&pending
))
1537 dapm_seq_run_coalesced(card
, &pending
);
1539 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1540 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1541 if (sort
[i
] == cur_sort
)
1542 cur_dapm
->seq_notifier(cur_dapm
,
1547 if (cur_dapm
&& w
->dapm
!= cur_dapm
)
1548 soc_dapm_async_complete(cur_dapm
);
1550 INIT_LIST_HEAD(&pending
);
1552 cur_subseq
= INT_MIN
;
1553 cur_reg
= SND_SOC_NOPM
;
1558 case snd_soc_dapm_pre
:
1560 list_for_each_entry_safe_continue(w
, n
, list
,
1563 if (event
== SND_SOC_DAPM_STREAM_START
)
1565 NULL
, SND_SOC_DAPM_PRE_PMU
);
1566 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1568 NULL
, SND_SOC_DAPM_PRE_PMD
);
1571 case snd_soc_dapm_post
:
1573 list_for_each_entry_safe_continue(w
, n
, list
,
1576 if (event
== SND_SOC_DAPM_STREAM_START
)
1578 NULL
, SND_SOC_DAPM_POST_PMU
);
1579 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1581 NULL
, SND_SOC_DAPM_POST_PMD
);
1585 /* Queue it up for application */
1586 cur_sort
= sort
[w
->id
];
1587 cur_subseq
= w
->subseq
;
1590 list_move(&w
->power_list
, &pending
);
1595 dev_err(w
->dapm
->dev
,
1596 "ASoC: Failed to apply widget power: %d\n", ret
);
1599 if (!list_empty(&pending
))
1600 dapm_seq_run_coalesced(card
, &pending
);
1602 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1603 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1604 if (sort
[i
] == cur_sort
)
1605 cur_dapm
->seq_notifier(cur_dapm
,
1609 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1610 soc_dapm_async_complete(d
);
1614 static void dapm_widget_update(struct snd_soc_card
*card
)
1616 struct snd_soc_dapm_update
*update
= card
->update
;
1617 struct snd_soc_dapm_widget_list
*wlist
;
1618 struct snd_soc_dapm_widget
*w
= NULL
;
1622 if (!update
|| !dapm_kcontrol_is_powered(update
->kcontrol
))
1625 wlist
= dapm_kcontrol_get_wlist(update
->kcontrol
);
1627 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1628 w
= wlist
->widgets
[wi
];
1630 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1631 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1633 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1641 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1644 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1647 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1648 w
= wlist
->widgets
[wi
];
1650 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1651 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1653 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1659 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1660 * they're changing state.
1662 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1664 struct snd_soc_dapm_context
*d
= data
;
1667 /* If we're off and we're not supposed to be go into STANDBY */
1668 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1669 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1671 pm_runtime_get_sync(d
->dev
);
1673 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1676 "ASoC: Failed to turn on bias: %d\n", ret
);
1679 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1680 if (d
->bias_level
!= d
->target_bias_level
) {
1681 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1684 "ASoC: Failed to prepare bias: %d\n", ret
);
1688 /* Async callback run prior to DAPM sequences - brings to their final
1691 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1693 struct snd_soc_dapm_context
*d
= data
;
1696 /* If we just powered the last thing off drop to standby bias */
1697 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1698 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1699 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1700 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1702 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1706 /* If we're in standby and can support bias off then do that */
1707 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1708 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1709 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1711 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1715 pm_runtime_put(d
->dev
);
1718 /* If we just powered up then move to active bias */
1719 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1720 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1721 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1723 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1728 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1729 bool power
, bool connect
)
1731 /* If a connection is being made or broken then that update
1732 * will have marked the peer dirty, otherwise the widgets are
1733 * not connected and this update has no impact. */
1737 /* If the peer is already in the state we're moving to then we
1738 * won't have an impact on it. */
1739 if (power
!= peer
->power
)
1740 dapm_mark_dirty(peer
, "peer state change");
1743 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1744 struct list_head
*up_list
,
1745 struct list_head
*down_list
)
1747 struct snd_soc_dapm_path
*path
;
1749 if (w
->power
== power
)
1752 trace_snd_soc_dapm_widget_power(w
, power
);
1754 /* If we changed our power state perhaps our neigbours changed
1757 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1759 dapm_widget_set_peer_power(path
->source
, power
,
1764 case snd_soc_dapm_supply
:
1765 case snd_soc_dapm_regulator_supply
:
1766 case snd_soc_dapm_clock_supply
:
1767 case snd_soc_dapm_kcontrol
:
1768 /* Supplies can't affect their outputs, only their inputs */
1771 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1773 dapm_widget_set_peer_power(path
->sink
, power
,
1781 dapm_seq_insert(w
, up_list
, true);
1783 dapm_seq_insert(w
, down_list
, false);
1786 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1787 struct list_head
*up_list
,
1788 struct list_head
*down_list
)
1793 case snd_soc_dapm_pre
:
1794 dapm_seq_insert(w
, down_list
, false);
1796 case snd_soc_dapm_post
:
1797 dapm_seq_insert(w
, up_list
, true);
1801 power
= dapm_widget_power_check(w
);
1803 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1809 * Scan each dapm widget for complete audio path.
1810 * A complete path is a route that has valid endpoints i.e.:-
1812 * o DAC to output pin.
1813 * o Input Pin to ADC.
1814 * o Input pin to Output pin (bypass, sidetone)
1815 * o DAC to ADC (loopback).
1817 static int dapm_power_widgets(struct snd_soc_card
*card
, int event
)
1819 struct snd_soc_dapm_widget
*w
;
1820 struct snd_soc_dapm_context
*d
;
1822 LIST_HEAD(down_list
);
1823 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1824 enum snd_soc_bias_level bias
;
1826 trace_snd_soc_dapm_start(card
);
1828 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1829 if (d
->idle_bias_off
)
1830 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1832 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1837 /* Check which widgets we need to power and store them in
1838 * lists indicating if they should be powered up or down. We
1839 * only check widgets that have been flagged as dirty but note
1840 * that new widgets may be added to the dirty list while we
1843 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1844 dapm_power_one_widget(w
, &up_list
, &down_list
);
1847 list_for_each_entry(w
, &card
->widgets
, list
) {
1849 case snd_soc_dapm_pre
:
1850 case snd_soc_dapm_post
:
1851 /* These widgets always need to be powered */
1854 list_del_init(&w
->dirty
);
1861 /* Supplies and micbiases only bring the
1862 * context up to STANDBY as unless something
1863 * else is active and passing audio they
1864 * generally don't require full power. Signal
1865 * generators are virtual pins and have no
1866 * power impact themselves.
1869 case snd_soc_dapm_siggen
:
1870 case snd_soc_dapm_vmid
:
1872 case snd_soc_dapm_supply
:
1873 case snd_soc_dapm_regulator_supply
:
1874 case snd_soc_dapm_clock_supply
:
1875 case snd_soc_dapm_micbias
:
1876 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1877 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1880 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1887 /* Force all contexts in the card to the same bias state if
1888 * they're not ground referenced.
1890 bias
= SND_SOC_BIAS_OFF
;
1891 list_for_each_entry(d
, &card
->dapm_list
, list
)
1892 if (d
->target_bias_level
> bias
)
1893 bias
= d
->target_bias_level
;
1894 list_for_each_entry(d
, &card
->dapm_list
, list
)
1895 if (!d
->idle_bias_off
)
1896 d
->target_bias_level
= bias
;
1898 trace_snd_soc_dapm_walk_done(card
);
1900 /* Run card bias changes at first */
1901 dapm_pre_sequence_async(&card
->dapm
, 0);
1902 /* Run other bias changes in parallel */
1903 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1904 if (d
!= &card
->dapm
)
1905 async_schedule_domain(dapm_pre_sequence_async
, d
,
1908 async_synchronize_full_domain(&async_domain
);
1910 list_for_each_entry(w
, &down_list
, power_list
) {
1911 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMD
);
1914 list_for_each_entry(w
, &up_list
, power_list
) {
1915 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMU
);
1918 /* Power down widgets first; try to avoid amplifying pops. */
1919 dapm_seq_run(card
, &down_list
, event
, false);
1921 dapm_widget_update(card
);
1924 dapm_seq_run(card
, &up_list
, event
, true);
1926 /* Run all the bias changes in parallel */
1927 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1928 if (d
!= &card
->dapm
)
1929 async_schedule_domain(dapm_post_sequence_async
, d
,
1932 async_synchronize_full_domain(&async_domain
);
1933 /* Run card bias changes at last */
1934 dapm_post_sequence_async(&card
->dapm
, 0);
1936 /* do we need to notify any clients that DAPM event is complete */
1937 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1938 if (d
->stream_event
)
1939 d
->stream_event(d
, event
);
1942 pop_dbg(card
->dev
, card
->pop_time
,
1943 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1944 pop_wait(card
->pop_time
);
1946 trace_snd_soc_dapm_done(card
);
1951 #ifdef CONFIG_DEBUG_FS
1952 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1953 char __user
*user_buf
,
1954 size_t count
, loff_t
*ppos
)
1956 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1960 struct snd_soc_dapm_path
*p
= NULL
;
1962 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1966 in
= is_connected_input_ep(w
, NULL
);
1967 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1968 out
= is_connected_output_ep(w
, NULL
);
1969 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1971 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1972 w
->name
, w
->power
? "On" : "Off",
1973 w
->force
? " (forced)" : "", in
, out
);
1976 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1977 " - R%d(0x%x) mask 0x%x",
1978 w
->reg
, w
->reg
, w
->mask
<< w
->shift
);
1980 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1983 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1985 w
->active
? "active" : "inactive");
1987 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1988 if (p
->connected
&& !p
->connected(w
, p
->source
))
1992 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1993 " in \"%s\" \"%s\"\n",
1994 p
->name
? p
->name
: "static",
1997 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1998 if (p
->connected
&& !p
->connected(w
, p
->sink
))
2002 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2003 " out \"%s\" \"%s\"\n",
2004 p
->name
? p
->name
: "static",
2008 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
2014 static const struct file_operations dapm_widget_power_fops
= {
2015 .open
= simple_open
,
2016 .read
= dapm_widget_power_read_file
,
2017 .llseek
= default_llseek
,
2020 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
2021 size_t count
, loff_t
*ppos
)
2023 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
2026 switch (dapm
->bias_level
) {
2027 case SND_SOC_BIAS_ON
:
2030 case SND_SOC_BIAS_PREPARE
:
2031 level
= "Prepare\n";
2033 case SND_SOC_BIAS_STANDBY
:
2034 level
= "Standby\n";
2036 case SND_SOC_BIAS_OFF
:
2040 WARN(1, "Unknown bias_level %d\n", dapm
->bias_level
);
2041 level
= "Unknown\n";
2045 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
2049 static const struct file_operations dapm_bias_fops
= {
2050 .open
= simple_open
,
2051 .read
= dapm_bias_read_file
,
2052 .llseek
= default_llseek
,
2055 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2056 struct dentry
*parent
)
2060 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
2062 if (!dapm
->debugfs_dapm
) {
2064 "ASoC: Failed to create DAPM debugfs directory\n");
2068 d
= debugfs_create_file("bias_level", 0444,
2069 dapm
->debugfs_dapm
, dapm
,
2073 "ASoC: Failed to create bias level debugfs file\n");
2076 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2078 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
2081 if (!dapm
->debugfs_dapm
|| !w
->name
)
2084 d
= debugfs_create_file(w
->name
, 0444,
2085 dapm
->debugfs_dapm
, w
,
2086 &dapm_widget_power_fops
);
2088 dev_warn(w
->dapm
->dev
,
2089 "ASoC: Failed to create %s debugfs file\n",
2093 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2095 debugfs_remove_recursive(dapm
->debugfs_dapm
);
2099 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2100 struct dentry
*parent
)
2104 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2108 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2114 /* test and update the power status of a mux widget */
2115 static int soc_dapm_mux_update_power(struct snd_soc_card
*card
,
2116 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
2118 struct snd_soc_dapm_path
*path
;
2121 /* find dapm widget path assoc with kcontrol */
2122 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2123 if (!path
->name
|| !e
->texts
[mux
])
2127 /* we now need to match the string in the enum to the path */
2128 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
2129 path
->connect
= 1; /* new connection */
2130 dapm_mark_dirty(path
->source
, "mux connection");
2133 dapm_mark_dirty(path
->source
,
2134 "mux disconnection");
2135 path
->connect
= 0; /* old connection must be powered down */
2137 dapm_mark_dirty(path
->sink
, "mux change");
2141 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2146 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context
*dapm
,
2147 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
,
2148 struct snd_soc_dapm_update
*update
)
2150 struct snd_soc_card
*card
= dapm
->card
;
2153 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2154 card
->update
= update
;
2155 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
2156 card
->update
= NULL
;
2157 mutex_unlock(&card
->dapm_mutex
);
2159 soc_dpcm_runtime_update(card
);
2162 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
2164 /* test and update the power status of a mixer or switch widget */
2165 static int soc_dapm_mixer_update_power(struct snd_soc_card
*card
,
2166 struct snd_kcontrol
*kcontrol
, int connect
)
2168 struct snd_soc_dapm_path
*path
;
2171 /* find dapm widget path assoc with kcontrol */
2172 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2174 path
->connect
= connect
;
2175 dapm_mark_dirty(path
->source
, "mixer connection");
2176 dapm_mark_dirty(path
->sink
, "mixer update");
2180 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2185 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context
*dapm
,
2186 struct snd_kcontrol
*kcontrol
, int connect
,
2187 struct snd_soc_dapm_update
*update
)
2189 struct snd_soc_card
*card
= dapm
->card
;
2192 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2193 card
->update
= update
;
2194 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
2195 card
->update
= NULL
;
2196 mutex_unlock(&card
->dapm_mutex
);
2198 soc_dpcm_runtime_update(card
);
2201 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2203 /* show dapm widget status in sys fs */
2204 static ssize_t
dapm_widget_show(struct device
*dev
,
2205 struct device_attribute
*attr
, char *buf
)
2207 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2208 struct snd_soc_codec
*codec
=rtd
->codec
;
2209 struct snd_soc_dapm_widget
*w
;
2211 char *state
= "not set";
2213 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
2214 if (w
->dapm
!= &codec
->dapm
)
2217 /* only display widgets that burnm power */
2219 case snd_soc_dapm_hp
:
2220 case snd_soc_dapm_mic
:
2221 case snd_soc_dapm_spk
:
2222 case snd_soc_dapm_line
:
2223 case snd_soc_dapm_micbias
:
2224 case snd_soc_dapm_dac
:
2225 case snd_soc_dapm_adc
:
2226 case snd_soc_dapm_pga
:
2227 case snd_soc_dapm_out_drv
:
2228 case snd_soc_dapm_mixer
:
2229 case snd_soc_dapm_mixer_named_ctl
:
2230 case snd_soc_dapm_supply
:
2231 case snd_soc_dapm_regulator_supply
:
2232 case snd_soc_dapm_clock_supply
:
2234 count
+= sprintf(buf
+ count
, "%s: %s\n",
2235 w
->name
, w
->power
? "On":"Off");
2242 switch (codec
->dapm
.bias_level
) {
2243 case SND_SOC_BIAS_ON
:
2246 case SND_SOC_BIAS_PREPARE
:
2249 case SND_SOC_BIAS_STANDBY
:
2252 case SND_SOC_BIAS_OFF
:
2256 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2261 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2263 int snd_soc_dapm_sys_add(struct device
*dev
)
2265 return device_create_file(dev
, &dev_attr_dapm_widget
);
2268 static void snd_soc_dapm_sys_remove(struct device
*dev
)
2270 device_remove_file(dev
, &dev_attr_dapm_widget
);
2273 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2275 list_del(&path
->list_sink
);
2276 list_del(&path
->list_source
);
2277 list_del(&path
->list_kcontrol
);
2278 list_del(&path
->list
);
2282 /* free all dapm widgets and resources */
2283 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2285 struct snd_soc_dapm_widget
*w
, *next_w
;
2286 struct snd_soc_dapm_path
*p
, *next_p
;
2288 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2289 if (w
->dapm
!= dapm
)
2293 * remove source and sink paths associated to this widget.
2294 * While removing the path, remove reference to it from both
2295 * source and sink widgets so that path is removed only once.
2297 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
)
2300 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
)
2303 kfree(w
->kcontrols
);
2309 static struct snd_soc_dapm_widget
*dapm_find_widget(
2310 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2311 bool search_other_contexts
)
2313 struct snd_soc_dapm_widget
*w
;
2314 struct snd_soc_dapm_widget
*fallback
= NULL
;
2316 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2317 if (!strcmp(w
->name
, pin
)) {
2318 if (w
->dapm
== dapm
)
2325 if (search_other_contexts
)
2331 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2332 const char *pin
, int status
)
2334 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2337 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2341 if (w
->connected
!= status
)
2342 dapm_mark_dirty(w
, "pin configuration");
2344 w
->connected
= status
;
2352 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2353 * @dapm: DAPM context
2355 * Walks all dapm audio paths and powers widgets according to their
2356 * stream or path usage.
2358 * Requires external locking.
2360 * Returns 0 for success.
2362 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context
*dapm
)
2365 * Suppress early reports (eg, jacks syncing their state) to avoid
2366 * silly DAPM runs during card startup.
2368 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2371 return dapm_power_widgets(dapm
->card
, SND_SOC_DAPM_STREAM_NOP
);
2373 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked
);
2376 * snd_soc_dapm_sync - scan and power dapm paths
2377 * @dapm: DAPM context
2379 * Walks all dapm audio paths and powers widgets according to their
2380 * stream or path usage.
2382 * Returns 0 for success.
2384 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2388 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2389 ret
= snd_soc_dapm_sync_unlocked(dapm
);
2390 mutex_unlock(&dapm
->card
->dapm_mutex
);
2393 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2395 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
2396 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
2397 const char *control
,
2398 int (*connected
)(struct snd_soc_dapm_widget
*source
,
2399 struct snd_soc_dapm_widget
*sink
))
2401 struct snd_soc_dapm_path
*path
;
2404 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2408 path
->source
= wsource
;
2410 path
->connected
= connected
;
2411 INIT_LIST_HEAD(&path
->list
);
2412 INIT_LIST_HEAD(&path
->list_kcontrol
);
2413 INIT_LIST_HEAD(&path
->list_source
);
2414 INIT_LIST_HEAD(&path
->list_sink
);
2416 /* check for external widgets */
2417 if (wsink
->id
== snd_soc_dapm_input
) {
2418 if (wsource
->id
== snd_soc_dapm_micbias
||
2419 wsource
->id
== snd_soc_dapm_mic
||
2420 wsource
->id
== snd_soc_dapm_line
||
2421 wsource
->id
== snd_soc_dapm_output
)
2424 if (wsource
->id
== snd_soc_dapm_output
) {
2425 if (wsink
->id
== snd_soc_dapm_spk
||
2426 wsink
->id
== snd_soc_dapm_hp
||
2427 wsink
->id
== snd_soc_dapm_line
||
2428 wsink
->id
== snd_soc_dapm_input
)
2432 dapm_mark_dirty(wsource
, "Route added");
2433 dapm_mark_dirty(wsink
, "Route added");
2435 /* connect static paths */
2436 if (control
== NULL
) {
2437 list_add(&path
->list
, &dapm
->card
->paths
);
2438 list_add(&path
->list_sink
, &wsink
->sources
);
2439 list_add(&path
->list_source
, &wsource
->sinks
);
2444 /* connect dynamic paths */
2445 switch (wsink
->id
) {
2446 case snd_soc_dapm_adc
:
2447 case snd_soc_dapm_dac
:
2448 case snd_soc_dapm_pga
:
2449 case snd_soc_dapm_out_drv
:
2450 case snd_soc_dapm_input
:
2451 case snd_soc_dapm_output
:
2452 case snd_soc_dapm_siggen
:
2453 case snd_soc_dapm_micbias
:
2454 case snd_soc_dapm_vmid
:
2455 case snd_soc_dapm_pre
:
2456 case snd_soc_dapm_post
:
2457 case snd_soc_dapm_supply
:
2458 case snd_soc_dapm_regulator_supply
:
2459 case snd_soc_dapm_clock_supply
:
2460 case snd_soc_dapm_aif_in
:
2461 case snd_soc_dapm_aif_out
:
2462 case snd_soc_dapm_dai_in
:
2463 case snd_soc_dapm_dai_out
:
2464 case snd_soc_dapm_dai_link
:
2465 case snd_soc_dapm_kcontrol
:
2466 list_add(&path
->list
, &dapm
->card
->paths
);
2467 list_add(&path
->list_sink
, &wsink
->sources
);
2468 list_add(&path
->list_source
, &wsource
->sinks
);
2471 case snd_soc_dapm_mux
:
2472 case snd_soc_dapm_virt_mux
:
2473 case snd_soc_dapm_value_mux
:
2474 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2475 &wsink
->kcontrol_news
[0]);
2479 case snd_soc_dapm_switch
:
2480 case snd_soc_dapm_mixer
:
2481 case snd_soc_dapm_mixer_named_ctl
:
2482 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2486 case snd_soc_dapm_hp
:
2487 case snd_soc_dapm_mic
:
2488 case snd_soc_dapm_line
:
2489 case snd_soc_dapm_spk
:
2490 list_add(&path
->list
, &dapm
->card
->paths
);
2491 list_add(&path
->list_sink
, &wsink
->sources
);
2492 list_add(&path
->list_source
, &wsource
->sinks
);
2503 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2504 const struct snd_soc_dapm_route
*route
,
2505 unsigned int is_prefixed
)
2507 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2508 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2511 char prefixed_sink
[80];
2512 char prefixed_source
[80];
2515 if (dapm
->codec
&& dapm
->codec
->name_prefix
&& !is_prefixed
) {
2516 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2517 dapm
->codec
->name_prefix
, route
->sink
);
2518 sink
= prefixed_sink
;
2519 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2520 dapm
->codec
->name_prefix
, route
->source
);
2521 source
= prefixed_source
;
2524 source
= route
->source
;
2528 * find src and dest widgets over all widgets but favor a widget from
2529 * current DAPM context
2531 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2532 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2534 if (w
->dapm
== dapm
)
2538 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2540 if (w
->dapm
== dapm
)
2544 /* use widget from another DAPM context if not found from this */
2550 if (wsource
== NULL
) {
2551 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2555 if (wsink
== NULL
) {
2556 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2561 ret
= snd_soc_dapm_add_path(dapm
, wsource
, wsink
, route
->control
,
2568 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2569 source
, route
->control
, sink
);
2573 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2574 const struct snd_soc_dapm_route
*route
)
2576 struct snd_soc_dapm_path
*path
, *p
;
2579 char prefixed_sink
[80];
2580 char prefixed_source
[80];
2582 if (route
->control
) {
2584 "ASoC: Removal of routes with controls not supported\n");
2588 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2589 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2590 dapm
->codec
->name_prefix
, route
->sink
);
2591 sink
= prefixed_sink
;
2592 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2593 dapm
->codec
->name_prefix
, route
->source
);
2594 source
= prefixed_source
;
2597 source
= route
->source
;
2601 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2602 if (strcmp(p
->source
->name
, source
) != 0)
2604 if (strcmp(p
->sink
->name
, sink
) != 0)
2611 dapm_mark_dirty(path
->source
, "Route removed");
2612 dapm_mark_dirty(path
->sink
, "Route removed");
2614 dapm_free_path(path
);
2616 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
2624 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2625 * @dapm: DAPM context
2626 * @route: audio routes
2627 * @num: number of routes
2629 * Connects 2 dapm widgets together via a named audio path. The sink is
2630 * the widget receiving the audio signal, whilst the source is the sender
2631 * of the audio signal.
2633 * Returns 0 for success else error. On error all resources can be freed
2634 * with a call to snd_soc_card_free().
2636 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2637 const struct snd_soc_dapm_route
*route
, int num
)
2641 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2642 for (i
= 0; i
< num
; i
++) {
2643 r
= snd_soc_dapm_add_route(dapm
, route
, false);
2645 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
2647 route
->control
? route
->control
: "direct",
2653 mutex_unlock(&dapm
->card
->dapm_mutex
);
2657 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2660 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2661 * @dapm: DAPM context
2662 * @route: audio routes
2663 * @num: number of routes
2665 * Removes routes from the DAPM context.
2667 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2668 const struct snd_soc_dapm_route
*route
, int num
)
2672 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2673 for (i
= 0; i
< num
; i
++) {
2674 snd_soc_dapm_del_route(dapm
, route
);
2677 mutex_unlock(&dapm
->card
->dapm_mutex
);
2681 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2683 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2684 const struct snd_soc_dapm_route
*route
)
2686 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2689 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2692 struct snd_soc_dapm_path
*path
;
2696 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
2702 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
2707 if (route
->control
|| route
->connected
)
2708 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
2709 route
->source
, route
->sink
);
2711 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2712 if (path
->sink
== sink
) {
2719 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
2720 route
->source
, route
->sink
);
2722 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
2723 count
, route
->source
, route
->sink
);
2729 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2730 * @dapm: DAPM context
2731 * @route: audio routes
2732 * @num: number of routes
2734 * Mark existing routes matching those specified in the passed array
2735 * as being weak, meaning that they are ignored for the purpose of
2736 * power decisions. The main intended use case is for sidetone paths
2737 * which couple audio between other independent paths if they are both
2738 * active in order to make the combination work better at the user
2739 * level but which aren't intended to be "used".
2741 * Note that CODEC drivers should not use this as sidetone type paths
2742 * can frequently also be used as bypass paths.
2744 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2745 const struct snd_soc_dapm_route
*route
, int num
)
2750 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2751 for (i
= 0; i
< num
; i
++) {
2752 err
= snd_soc_dapm_weak_route(dapm
, route
);
2757 mutex_unlock(&dapm
->card
->dapm_mutex
);
2761 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2764 * snd_soc_dapm_new_widgets - add new dapm widgets
2765 * @dapm: DAPM context
2767 * Checks the codec for any new dapm widgets and creates them if found.
2769 * Returns 0 for success.
2771 int snd_soc_dapm_new_widgets(struct snd_soc_card
*card
)
2773 struct snd_soc_dapm_widget
*w
;
2776 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2778 list_for_each_entry(w
, &card
->widgets
, list
)
2783 if (w
->num_kcontrols
) {
2784 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2785 sizeof(struct snd_kcontrol
*),
2787 if (!w
->kcontrols
) {
2788 mutex_unlock(&card
->dapm_mutex
);
2794 case snd_soc_dapm_switch
:
2795 case snd_soc_dapm_mixer
:
2796 case snd_soc_dapm_mixer_named_ctl
:
2799 case snd_soc_dapm_mux
:
2800 case snd_soc_dapm_virt_mux
:
2801 case snd_soc_dapm_value_mux
:
2804 case snd_soc_dapm_pga
:
2805 case snd_soc_dapm_out_drv
:
2812 /* Read the initial power state from the device */
2814 soc_widget_read(w
, w
->reg
, &val
);
2815 val
= val
>> w
->shift
;
2817 if (val
== w
->on_val
)
2823 dapm_mark_dirty(w
, "new widget");
2824 dapm_debugfs_add_widget(w
);
2827 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2828 mutex_unlock(&card
->dapm_mutex
);
2831 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2834 * snd_soc_dapm_get_volsw - dapm mixer get callback
2835 * @kcontrol: mixer control
2836 * @ucontrol: control element information
2838 * Callback to get the value of a dapm mixer control.
2840 * Returns 0 for success.
2842 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2843 struct snd_ctl_elem_value
*ucontrol
)
2845 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2846 struct snd_soc_card
*card
= codec
->card
;
2847 struct soc_mixer_control
*mc
=
2848 (struct soc_mixer_control
*)kcontrol
->private_value
;
2850 unsigned int shift
= mc
->shift
;
2852 unsigned int mask
= (1 << fls(max
)) - 1;
2853 unsigned int invert
= mc
->invert
;
2856 if (snd_soc_volsw_is_stereo(mc
))
2857 dev_warn(codec
->dapm
.dev
,
2858 "ASoC: Control '%s' is stereo, which is not supported\n",
2861 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2862 if (dapm_kcontrol_is_powered(kcontrol
) && reg
!= SND_SOC_NOPM
)
2863 val
= (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2865 val
= dapm_kcontrol_get_value(kcontrol
);
2866 mutex_unlock(&card
->dapm_mutex
);
2869 ucontrol
->value
.integer
.value
[0] = max
- val
;
2871 ucontrol
->value
.integer
.value
[0] = val
;
2875 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2878 * snd_soc_dapm_put_volsw - dapm mixer set callback
2879 * @kcontrol: mixer control
2880 * @ucontrol: control element information
2882 * Callback to set the value of a dapm mixer control.
2884 * Returns 0 for success.
2886 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2887 struct snd_ctl_elem_value
*ucontrol
)
2889 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2890 struct snd_soc_card
*card
= codec
->card
;
2891 struct soc_mixer_control
*mc
=
2892 (struct soc_mixer_control
*)kcontrol
->private_value
;
2894 unsigned int shift
= mc
->shift
;
2896 unsigned int mask
= (1 << fls(max
)) - 1;
2897 unsigned int invert
= mc
->invert
;
2899 int connect
, change
;
2900 struct snd_soc_dapm_update update
;
2903 if (snd_soc_volsw_is_stereo(mc
))
2904 dev_warn(codec
->dapm
.dev
,
2905 "ASoC: Control '%s' is stereo, which is not supported\n",
2908 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2914 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2916 change
= dapm_kcontrol_set_value(kcontrol
, val
);
2918 if (reg
!= SND_SOC_NOPM
) {
2919 mask
= mask
<< shift
;
2922 change
= snd_soc_test_bits(codec
, reg
, mask
, val
);
2926 if (reg
!= SND_SOC_NOPM
) {
2927 update
.kcontrol
= kcontrol
;
2932 card
->update
= &update
;
2935 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
2937 card
->update
= NULL
;
2940 mutex_unlock(&card
->dapm_mutex
);
2943 soc_dpcm_runtime_update(card
);
2947 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2950 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2951 * @kcontrol: mixer control
2952 * @ucontrol: control element information
2954 * Callback to get the value of a dapm enumerated double mixer control.
2956 * Returns 0 for success.
2958 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2959 struct snd_ctl_elem_value
*ucontrol
)
2961 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2962 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2965 val
= snd_soc_read(codec
, e
->reg
);
2966 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & e
->mask
;
2967 if (e
->shift_l
!= e
->shift_r
)
2968 ucontrol
->value
.enumerated
.item
[1] =
2969 (val
>> e
->shift_r
) & e
->mask
;
2973 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2976 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2977 * @kcontrol: mixer control
2978 * @ucontrol: control element information
2980 * Callback to set the value of a dapm enumerated double mixer control.
2982 * Returns 0 for success.
2984 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2985 struct snd_ctl_elem_value
*ucontrol
)
2987 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2988 struct snd_soc_card
*card
= codec
->card
;
2989 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2990 unsigned int val
, mux
, change
;
2992 struct snd_soc_dapm_update update
;
2995 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2997 mux
= ucontrol
->value
.enumerated
.item
[0];
2998 val
= mux
<< e
->shift_l
;
2999 mask
= e
->mask
<< e
->shift_l
;
3000 if (e
->shift_l
!= e
->shift_r
) {
3001 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
3003 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
3004 mask
|= e
->mask
<< e
->shift_r
;
3007 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3009 change
= snd_soc_test_bits(codec
, e
->reg
, mask
, val
);
3011 update
.kcontrol
= kcontrol
;
3012 update
.reg
= e
->reg
;
3015 card
->update
= &update
;
3017 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
3019 card
->update
= NULL
;
3022 mutex_unlock(&card
->dapm_mutex
);
3025 soc_dpcm_runtime_update(card
);
3029 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
3032 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
3033 * @kcontrol: mixer control
3034 * @ucontrol: control element information
3036 * Returns 0 for success.
3038 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
3039 struct snd_ctl_elem_value
*ucontrol
)
3041 ucontrol
->value
.enumerated
.item
[0] = dapm_kcontrol_get_value(kcontrol
);
3044 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
3047 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
3048 * @kcontrol: mixer control
3049 * @ucontrol: control element information
3051 * Returns 0 for success.
3053 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
3054 struct snd_ctl_elem_value
*ucontrol
)
3056 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
3057 struct snd_soc_card
*card
= codec
->card
;
3059 struct soc_enum
*e
=
3060 (struct soc_enum
*)kcontrol
->private_value
;
3064 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
3067 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3069 value
= ucontrol
->value
.enumerated
.item
[0];
3070 change
= dapm_kcontrol_set_value(kcontrol
, value
);
3072 ret
= soc_dapm_mux_update_power(card
, kcontrol
, value
, e
);
3074 mutex_unlock(&card
->dapm_mutex
);
3077 soc_dpcm_runtime_update(card
);
3081 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
3084 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
3086 * @kcontrol: mixer control
3087 * @ucontrol: control element information
3089 * Callback to get the value of a dapm semi enumerated double mixer control.
3091 * Semi enumerated mixer: the enumerated items are referred as values. Can be
3092 * used for handling bitfield coded enumeration for example.
3094 * Returns 0 for success.
3096 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
3097 struct snd_ctl_elem_value
*ucontrol
)
3099 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
3100 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3101 unsigned int reg_val
, val
, mux
;
3103 reg_val
= snd_soc_read(codec
, e
->reg
);
3104 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
3105 for (mux
= 0; mux
< e
->max
; mux
++) {
3106 if (val
== e
->values
[mux
])
3109 ucontrol
->value
.enumerated
.item
[0] = mux
;
3110 if (e
->shift_l
!= e
->shift_r
) {
3111 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
3112 for (mux
= 0; mux
< e
->max
; mux
++) {
3113 if (val
== e
->values
[mux
])
3116 ucontrol
->value
.enumerated
.item
[1] = mux
;
3121 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
3124 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
3126 * @kcontrol: mixer control
3127 * @ucontrol: control element information
3129 * Callback to set the value of a dapm semi enumerated double mixer control.
3131 * Semi enumerated mixer: the enumerated items are referred as values. Can be
3132 * used for handling bitfield coded enumeration for example.
3134 * Returns 0 for success.
3136 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
3137 struct snd_ctl_elem_value
*ucontrol
)
3139 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
3140 struct snd_soc_card
*card
= codec
->card
;
3141 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3142 unsigned int val
, mux
, change
;
3144 struct snd_soc_dapm_update update
;
3147 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
3149 mux
= ucontrol
->value
.enumerated
.item
[0];
3150 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
3151 mask
= e
->mask
<< e
->shift_l
;
3152 if (e
->shift_l
!= e
->shift_r
) {
3153 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
3155 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
3156 mask
|= e
->mask
<< e
->shift_r
;
3159 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3161 change
= snd_soc_test_bits(codec
, e
->reg
, mask
, val
);
3163 update
.kcontrol
= kcontrol
;
3164 update
.reg
= e
->reg
;
3167 card
->update
= &update
;
3169 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
3171 card
->update
= NULL
;
3174 mutex_unlock(&card
->dapm_mutex
);
3177 soc_dpcm_runtime_update(card
);
3181 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
3184 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3186 * @kcontrol: mixer control
3187 * @uinfo: control element information
3189 * Callback to provide information about a pin switch control.
3191 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3192 struct snd_ctl_elem_info
*uinfo
)
3194 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3196 uinfo
->value
.integer
.min
= 0;
3197 uinfo
->value
.integer
.max
= 1;
3201 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3204 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3206 * @kcontrol: mixer control
3209 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3210 struct snd_ctl_elem_value
*ucontrol
)
3212 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3213 const char *pin
= (const char *)kcontrol
->private_value
;
3215 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3217 ucontrol
->value
.integer
.value
[0] =
3218 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3220 mutex_unlock(&card
->dapm_mutex
);
3224 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3227 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3229 * @kcontrol: mixer control
3232 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3233 struct snd_ctl_elem_value
*ucontrol
)
3235 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3236 const char *pin
= (const char *)kcontrol
->private_value
;
3238 if (ucontrol
->value
.integer
.value
[0])
3239 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3241 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3243 snd_soc_dapm_sync(&card
->dapm
);
3246 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3248 static struct snd_soc_dapm_widget
*
3249 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3250 const struct snd_soc_dapm_widget
*widget
)
3252 struct snd_soc_dapm_widget
*w
;
3255 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3259 case snd_soc_dapm_regulator_supply
:
3260 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3261 if (IS_ERR(w
->regulator
)) {
3262 ret
= PTR_ERR(w
->regulator
);
3263 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3268 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3269 ret
= regulator_allow_bypass(w
->regulator
, true);
3271 dev_warn(w
->dapm
->dev
,
3272 "ASoC: Failed to bypass %s: %d\n",
3276 case snd_soc_dapm_clock_supply
:
3277 #ifdef CONFIG_CLKDEV_LOOKUP
3278 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3279 if (IS_ERR(w
->clk
)) {
3280 ret
= PTR_ERR(w
->clk
);
3281 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3293 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3294 w
->name
= kasprintf(GFP_KERNEL
, "%s %s",
3295 dapm
->codec
->name_prefix
, widget
->name
);
3297 w
->name
= kasprintf(GFP_KERNEL
, "%s", widget
->name
);
3299 if (w
->name
== NULL
) {
3305 case snd_soc_dapm_switch
:
3306 case snd_soc_dapm_mixer
:
3307 case snd_soc_dapm_mixer_named_ctl
:
3308 w
->power_check
= dapm_generic_check_power
;
3310 case snd_soc_dapm_mux
:
3311 case snd_soc_dapm_virt_mux
:
3312 case snd_soc_dapm_value_mux
:
3313 w
->power_check
= dapm_generic_check_power
;
3315 case snd_soc_dapm_dai_out
:
3316 w
->power_check
= dapm_adc_check_power
;
3318 case snd_soc_dapm_dai_in
:
3319 w
->power_check
= dapm_dac_check_power
;
3321 case snd_soc_dapm_adc
:
3322 case snd_soc_dapm_aif_out
:
3323 case snd_soc_dapm_dac
:
3324 case snd_soc_dapm_aif_in
:
3325 case snd_soc_dapm_pga
:
3326 case snd_soc_dapm_out_drv
:
3327 case snd_soc_dapm_input
:
3328 case snd_soc_dapm_output
:
3329 case snd_soc_dapm_micbias
:
3330 case snd_soc_dapm_spk
:
3331 case snd_soc_dapm_hp
:
3332 case snd_soc_dapm_mic
:
3333 case snd_soc_dapm_line
:
3334 case snd_soc_dapm_dai_link
:
3335 w
->power_check
= dapm_generic_check_power
;
3337 case snd_soc_dapm_supply
:
3338 case snd_soc_dapm_regulator_supply
:
3339 case snd_soc_dapm_clock_supply
:
3340 case snd_soc_dapm_kcontrol
:
3341 w
->power_check
= dapm_supply_check_power
;
3344 w
->power_check
= dapm_always_on_check_power
;
3349 w
->codec
= dapm
->codec
;
3350 w
->platform
= dapm
->platform
;
3351 INIT_LIST_HEAD(&w
->sources
);
3352 INIT_LIST_HEAD(&w
->sinks
);
3353 INIT_LIST_HEAD(&w
->list
);
3354 INIT_LIST_HEAD(&w
->dirty
);
3355 list_add(&w
->list
, &dapm
->card
->widgets
);
3357 /* machine layer set ups unconnected pins and insertions */
3363 * snd_soc_dapm_new_controls - create new dapm controls
3364 * @dapm: DAPM context
3365 * @widget: widget array
3366 * @num: number of widgets
3368 * Creates new DAPM controls based upon the templates.
3370 * Returns 0 for success else error.
3372 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3373 const struct snd_soc_dapm_widget
*widget
,
3376 struct snd_soc_dapm_widget
*w
;
3380 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3381 for (i
= 0; i
< num
; i
++) {
3382 w
= snd_soc_dapm_new_control(dapm
, widget
);
3385 "ASoC: Failed to create DAPM control %s\n",
3392 mutex_unlock(&dapm
->card
->dapm_mutex
);
3395 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3397 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3398 struct snd_kcontrol
*kcontrol
, int event
)
3400 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3401 struct snd_soc_dai
*source
, *sink
;
3402 const struct snd_soc_pcm_stream
*config
= w
->params
;
3403 struct snd_pcm_substream substream
;
3404 struct snd_pcm_hw_params
*params
= NULL
;
3408 if (WARN_ON(!config
) ||
3409 WARN_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
)))
3412 /* We only support a single source and sink, pick the first */
3413 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3415 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3418 if (WARN_ON(!source_p
|| !sink_p
) ||
3419 WARN_ON(!sink_p
->source
|| !source_p
->sink
) ||
3420 WARN_ON(!source_p
->source
|| !sink_p
->sink
))
3423 source
= source_p
->source
->priv
;
3424 sink
= sink_p
->sink
->priv
;
3426 /* Be a little careful as we don't want to overflow the mask array */
3427 if (config
->formats
) {
3428 fmt
= ffs(config
->formats
) - 1;
3430 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3435 /* Currently very limited parameter selection */
3436 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3441 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3443 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3445 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3448 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3449 = config
->channels_min
;
3450 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3451 = config
->channels_max
;
3453 memset(&substream
, 0, sizeof(substream
));
3456 case SND_SOC_DAPM_PRE_PMU
:
3457 if (source
->driver
->ops
&& source
->driver
->ops
->hw_params
) {
3458 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3459 ret
= source
->driver
->ops
->hw_params(&substream
,
3462 dev_err(source
->dev
,
3463 "ASoC: hw_params() failed: %d\n", ret
);
3468 if (sink
->driver
->ops
&& sink
->driver
->ops
->hw_params
) {
3469 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3470 ret
= sink
->driver
->ops
->hw_params(&substream
, params
,
3474 "ASoC: hw_params() failed: %d\n", ret
);
3480 case SND_SOC_DAPM_POST_PMU
:
3481 ret
= snd_soc_dai_digital_mute(sink
, 0,
3482 SNDRV_PCM_STREAM_PLAYBACK
);
3483 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3484 dev_warn(sink
->dev
, "ASoC: Failed to unmute: %d\n", ret
);
3488 case SND_SOC_DAPM_PRE_PMD
:
3489 ret
= snd_soc_dai_digital_mute(sink
, 1,
3490 SNDRV_PCM_STREAM_PLAYBACK
);
3491 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3492 dev_warn(sink
->dev
, "ASoC: Failed to mute: %d\n", ret
);
3497 WARN(1, "Unknown event %d\n", event
);
3506 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3507 const struct snd_soc_pcm_stream
*params
,
3508 struct snd_soc_dapm_widget
*source
,
3509 struct snd_soc_dapm_widget
*sink
)
3511 struct snd_soc_dapm_route routes
[2];
3512 struct snd_soc_dapm_widget
template;
3513 struct snd_soc_dapm_widget
*w
;
3517 len
= strlen(source
->name
) + strlen(sink
->name
) + 2;
3518 link_name
= devm_kzalloc(card
->dev
, len
, GFP_KERNEL
);
3521 snprintf(link_name
, len
, "%s-%s", source
->name
, sink
->name
);
3523 memset(&template, 0, sizeof(template));
3524 template.reg
= SND_SOC_NOPM
;
3525 template.id
= snd_soc_dapm_dai_link
;
3526 template.name
= link_name
;
3527 template.event
= snd_soc_dai_link_event
;
3528 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3529 SND_SOC_DAPM_PRE_PMD
;
3531 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
3533 w
= snd_soc_dapm_new_control(&card
->dapm
, &template);
3535 dev_err(card
->dev
, "ASoC: Failed to create %s widget\n",
3542 memset(&routes
, 0, sizeof(routes
));
3544 routes
[0].source
= source
->name
;
3545 routes
[0].sink
= link_name
;
3546 routes
[1].source
= link_name
;
3547 routes
[1].sink
= sink
->name
;
3549 return snd_soc_dapm_add_routes(&card
->dapm
, routes
,
3550 ARRAY_SIZE(routes
));
3553 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3554 struct snd_soc_dai
*dai
)
3556 struct snd_soc_dapm_widget
template;
3557 struct snd_soc_dapm_widget
*w
;
3559 WARN_ON(dapm
->dev
!= dai
->dev
);
3561 memset(&template, 0, sizeof(template));
3562 template.reg
= SND_SOC_NOPM
;
3564 if (dai
->driver
->playback
.stream_name
) {
3565 template.id
= snd_soc_dapm_dai_in
;
3566 template.name
= dai
->driver
->playback
.stream_name
;
3567 template.sname
= dai
->driver
->playback
.stream_name
;
3569 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3572 w
= snd_soc_dapm_new_control(dapm
, &template);
3574 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3575 dai
->driver
->playback
.stream_name
);
3580 dai
->playback_widget
= w
;
3583 if (dai
->driver
->capture
.stream_name
) {
3584 template.id
= snd_soc_dapm_dai_out
;
3585 template.name
= dai
->driver
->capture
.stream_name
;
3586 template.sname
= dai
->driver
->capture
.stream_name
;
3588 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3591 w
= snd_soc_dapm_new_control(dapm
, &template);
3593 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3594 dai
->driver
->capture
.stream_name
);
3599 dai
->capture_widget
= w
;
3605 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3607 struct snd_soc_dapm_widget
*dai_w
, *w
;
3608 struct snd_soc_dai
*dai
;
3610 /* For each DAI widget... */
3611 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3612 switch (dai_w
->id
) {
3613 case snd_soc_dapm_dai_in
:
3614 case snd_soc_dapm_dai_out
:
3622 /* ...find all widgets with the same stream and link them */
3623 list_for_each_entry(w
, &card
->widgets
, list
) {
3624 if (w
->dapm
!= dai_w
->dapm
)
3628 case snd_soc_dapm_dai_in
:
3629 case snd_soc_dapm_dai_out
:
3635 if (!w
->sname
|| !strstr(w
->sname
, dai_w
->name
))
3638 if (dai
->driver
->playback
.stream_name
&&
3640 dai
->driver
->playback
.stream_name
)) {
3641 dev_dbg(dai
->dev
, "%s -> %s\n",
3642 dai
->playback_widget
->name
, w
->name
);
3644 snd_soc_dapm_add_path(w
->dapm
,
3645 dai
->playback_widget
, w
, NULL
, NULL
);
3648 if (dai
->driver
->capture
.stream_name
&&
3650 dai
->driver
->capture
.stream_name
)) {
3651 dev_dbg(dai
->dev
, "%s -> %s\n",
3652 w
->name
, dai
->capture_widget
->name
);
3654 snd_soc_dapm_add_path(w
->dapm
, w
,
3655 dai
->capture_widget
, NULL
, NULL
);
3663 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card
*card
)
3665 struct snd_soc_pcm_runtime
*rtd
= card
->rtd
;
3666 struct snd_soc_dai
*cpu_dai
, *codec_dai
;
3667 struct snd_soc_dapm_route r
;
3670 memset(&r
, 0, sizeof(r
));
3672 /* for each BE DAI link... */
3673 for (i
= 0; i
< card
->num_rtd
; i
++) {
3674 rtd
= &card
->rtd
[i
];
3675 cpu_dai
= rtd
->cpu_dai
;
3676 codec_dai
= rtd
->codec_dai
;
3678 /* dynamic FE links have no fixed DAI mapping */
3679 if (rtd
->dai_link
->dynamic
)
3682 /* there is no point in connecting BE DAI links with dummies */
3683 if (snd_soc_dai_is_dummy(codec_dai
) ||
3684 snd_soc_dai_is_dummy(cpu_dai
))
3687 /* connect BE DAI playback if widgets are valid */
3688 if (codec_dai
->playback_widget
&& cpu_dai
->playback_widget
) {
3689 r
.source
= cpu_dai
->playback_widget
->name
;
3690 r
.sink
= codec_dai
->playback_widget
->name
;
3691 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3692 cpu_dai
->codec
->name
, r
.source
,
3693 codec_dai
->platform
->name
, r
.sink
);
3695 snd_soc_dapm_add_route(&card
->dapm
, &r
, true);
3698 /* connect BE DAI capture if widgets are valid */
3699 if (codec_dai
->capture_widget
&& cpu_dai
->capture_widget
) {
3700 r
.source
= codec_dai
->capture_widget
->name
;
3701 r
.sink
= cpu_dai
->capture_widget
->name
;
3702 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3703 codec_dai
->codec
->name
, r
.source
,
3704 cpu_dai
->platform
->name
, r
.sink
);
3706 snd_soc_dapm_add_route(&card
->dapm
, &r
, true);
3712 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3716 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
3717 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3718 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
3720 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3721 w_cpu
= cpu_dai
->playback_widget
;
3722 w_codec
= codec_dai
->playback_widget
;
3724 w_cpu
= cpu_dai
->capture_widget
;
3725 w_codec
= codec_dai
->capture_widget
;
3730 dapm_mark_dirty(w_cpu
, "stream event");
3733 case SND_SOC_DAPM_STREAM_START
:
3736 case SND_SOC_DAPM_STREAM_STOP
:
3739 case SND_SOC_DAPM_STREAM_SUSPEND
:
3740 case SND_SOC_DAPM_STREAM_RESUME
:
3741 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3742 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3749 dapm_mark_dirty(w_codec
, "stream event");
3752 case SND_SOC_DAPM_STREAM_START
:
3753 w_codec
->active
= 1;
3755 case SND_SOC_DAPM_STREAM_STOP
:
3756 w_codec
->active
= 0;
3758 case SND_SOC_DAPM_STREAM_SUSPEND
:
3759 case SND_SOC_DAPM_STREAM_RESUME
:
3760 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3761 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3766 dapm_power_widgets(rtd
->card
, event
);
3770 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3771 * @rtd: PCM runtime data
3772 * @stream: stream name
3773 * @event: stream event
3775 * Sends a stream event to the dapm core. The core then makes any
3776 * necessary widget power changes.
3778 * Returns 0 for success else error.
3780 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3783 struct snd_soc_card
*card
= rtd
->card
;
3785 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3786 soc_dapm_stream_event(rtd
, stream
, event
);
3787 mutex_unlock(&card
->dapm_mutex
);
3791 * snd_soc_dapm_enable_pin_unlocked - enable pin.
3792 * @dapm: DAPM context
3795 * Enables input/output pin and its parents or children widgets iff there is
3796 * a valid audio route and active audio stream.
3798 * Requires external locking.
3800 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3801 * do any widget power switching.
3803 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3806 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3808 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked
);
3811 * snd_soc_dapm_enable_pin - enable pin.
3812 * @dapm: DAPM context
3815 * Enables input/output pin and its parents or children widgets iff there is
3816 * a valid audio route and active audio stream.
3818 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3819 * do any widget power switching.
3821 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3825 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3827 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 1);
3829 mutex_unlock(&dapm
->card
->dapm_mutex
);
3833 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3836 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
3837 * @dapm: DAPM context
3840 * Enables input/output pin regardless of any other state. This is
3841 * intended for use with microphone bias supplies used in microphone
3844 * Requires external locking.
3846 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3847 * do any widget power switching.
3849 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3852 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3855 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
3859 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
3862 dapm_mark_dirty(w
, "force enable");
3866 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked
);
3869 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3870 * @dapm: DAPM context
3873 * Enables input/output pin regardless of any other state. This is
3874 * intended for use with microphone bias supplies used in microphone
3877 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3878 * do any widget power switching.
3880 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3885 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3887 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
3889 mutex_unlock(&dapm
->card
->dapm_mutex
);
3893 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3896 * snd_soc_dapm_disable_pin_unlocked - disable pin.
3897 * @dapm: DAPM context
3900 * Disables input/output pin and its parents or children widgets.
3902 * Requires external locking.
3904 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3905 * do any widget power switching.
3907 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3910 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3912 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked
);
3915 * snd_soc_dapm_disable_pin - disable pin.
3916 * @dapm: DAPM context
3919 * Disables input/output pin and its parents or children widgets.
3921 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3922 * do any widget power switching.
3924 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3929 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3931 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
3933 mutex_unlock(&dapm
->card
->dapm_mutex
);
3937 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3940 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
3941 * @dapm: DAPM context
3944 * Marks the specified pin as being not connected, disabling it along
3945 * any parent or child widgets. At present this is identical to
3946 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3947 * additional things such as disabling controls which only affect
3948 * paths through the pin.
3950 * Requires external locking.
3952 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3953 * do any widget power switching.
3955 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3958 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3960 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked
);
3963 * snd_soc_dapm_nc_pin - permanently disable pin.
3964 * @dapm: DAPM context
3967 * Marks the specified pin as being not connected, disabling it along
3968 * any parent or child widgets. At present this is identical to
3969 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3970 * additional things such as disabling controls which only affect
3971 * paths through the pin.
3973 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3974 * do any widget power switching.
3976 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3980 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3982 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
3984 mutex_unlock(&dapm
->card
->dapm_mutex
);
3988 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3991 * snd_soc_dapm_get_pin_status - get audio pin status
3992 * @dapm: DAPM context
3993 * @pin: audio signal pin endpoint (or start point)
3995 * Get audio pin status - connected or disconnected.
3997 * Returns 1 for connected otherwise 0.
3999 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
4002 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4005 return w
->connected
;
4009 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
4012 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4013 * @dapm: DAPM context
4014 * @pin: audio signal pin endpoint (or start point)
4016 * Mark the given endpoint or pin as ignoring suspend. When the
4017 * system is disabled a path between two endpoints flagged as ignoring
4018 * suspend will not be disabled. The path must already be enabled via
4019 * normal means at suspend time, it will not be turned on if it was not
4022 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
4025 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
4028 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4032 w
->ignore_suspend
= 1;
4036 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
4038 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
4039 struct snd_soc_dapm_widget
*w
)
4041 struct snd_soc_dapm_path
*p
;
4043 list_for_each_entry(p
, &card
->paths
, list
) {
4044 if ((p
->source
== w
) || (p
->sink
== w
)) {
4046 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
4047 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
4048 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
4050 /* Connected to something other than the codec */
4051 if (p
->source
->dapm
!= p
->sink
->dapm
)
4054 * Loopback connection from codec external pin to
4055 * codec external pin
4057 if (p
->sink
->id
== snd_soc_dapm_input
) {
4058 switch (p
->source
->id
) {
4059 case snd_soc_dapm_output
:
4060 case snd_soc_dapm_micbias
:
4073 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
4074 * @codec: The codec whose pins should be processed
4076 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
4077 * which are unused. Pins are used if they are connected externally to the
4078 * codec, whether that be to some other device, or a loop-back connection to
4081 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
4083 struct snd_soc_card
*card
= codec
->card
;
4084 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
4085 struct snd_soc_dapm_widget
*w
;
4087 dev_dbg(codec
->dev
, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n",
4088 &card
->dapm
, &codec
->dapm
);
4090 list_for_each_entry(w
, &card
->widgets
, list
) {
4091 if (w
->dapm
!= dapm
)
4094 case snd_soc_dapm_input
:
4095 case snd_soc_dapm_output
:
4096 case snd_soc_dapm_micbias
:
4097 dev_dbg(codec
->dev
, "ASoC: Auto NC: Checking widget %s\n",
4099 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
4101 "... Not in map; disabling\n");
4102 snd_soc_dapm_nc_pin(dapm
, w
->name
);
4112 * snd_soc_dapm_free - free dapm resources
4113 * @dapm: DAPM context
4115 * Free all dapm widgets and resources.
4117 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
4119 snd_soc_dapm_sys_remove(dapm
->dev
);
4120 dapm_debugfs_cleanup(dapm
);
4121 dapm_free_widgets(dapm
);
4122 list_del(&dapm
->list
);
4124 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
4126 static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context
*dapm
)
4128 struct snd_soc_card
*card
= dapm
->card
;
4129 struct snd_soc_dapm_widget
*w
;
4130 LIST_HEAD(down_list
);
4133 mutex_lock(&card
->dapm_mutex
);
4135 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
4136 if (w
->dapm
!= dapm
)
4139 dapm_seq_insert(w
, &down_list
, false);
4145 /* If there were no widgets to power down we're already in
4149 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
4150 snd_soc_dapm_set_bias_level(dapm
,
4151 SND_SOC_BIAS_PREPARE
);
4152 dapm_seq_run(card
, &down_list
, 0, false);
4153 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
4154 snd_soc_dapm_set_bias_level(dapm
,
4155 SND_SOC_BIAS_STANDBY
);
4158 mutex_unlock(&card
->dapm_mutex
);
4162 * snd_soc_dapm_shutdown - callback for system shutdown
4164 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
4166 struct snd_soc_dapm_context
*dapm
;
4168 list_for_each_entry(dapm
, &card
->dapm_list
, list
) {
4169 if (dapm
!= &card
->dapm
) {
4170 soc_dapm_shutdown_dapm(dapm
);
4171 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
)
4172 snd_soc_dapm_set_bias_level(dapm
,
4177 soc_dapm_shutdown_dapm(&card
->dapm
);
4178 if (card
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
4179 snd_soc_dapm_set_bias_level(&card
->dapm
,
4183 /* Module information */
4184 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4185 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4186 MODULE_LICENSE("GPL");