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 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
);
157 EXPORT_SYMBOL_GPL(dapm_mark_dirty
);
159 void dapm_mark_io_dirty(struct snd_soc_dapm_context
*dapm
)
161 struct snd_soc_card
*card
= dapm
->card
;
162 struct snd_soc_dapm_widget
*w
;
164 mutex_lock(&card
->dapm_mutex
);
166 list_for_each_entry(w
, &card
->widgets
, list
) {
168 case snd_soc_dapm_input
:
169 case snd_soc_dapm_output
:
170 dapm_mark_dirty(w
, "Rechecking inputs and outputs");
177 mutex_unlock(&card
->dapm_mutex
);
179 EXPORT_SYMBOL_GPL(dapm_mark_io_dirty
);
181 /* create a new dapm widget */
182 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
183 const struct snd_soc_dapm_widget
*_widget
)
185 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
188 struct dapm_kcontrol_data
{
190 struct snd_soc_dapm_widget
*widget
;
191 struct list_head paths
;
192 struct snd_soc_dapm_widget_list
*wlist
;
195 static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget
*widget
,
196 struct snd_kcontrol
*kcontrol
)
198 struct dapm_kcontrol_data
*data
;
199 struct soc_mixer_control
*mc
;
201 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
203 dev_err(widget
->dapm
->dev
,
204 "ASoC: can't allocate kcontrol data for %s\n",
209 INIT_LIST_HEAD(&data
->paths
);
211 switch (widget
->id
) {
212 case snd_soc_dapm_switch
:
213 case snd_soc_dapm_mixer
:
214 case snd_soc_dapm_mixer_named_ctl
:
215 mc
= (struct soc_mixer_control
*)kcontrol
->private_value
;
217 if (mc
->autodisable
) {
218 struct snd_soc_dapm_widget
template;
220 memset(&template, 0, sizeof(template));
221 template.reg
= mc
->reg
;
222 template.mask
= (1 << fls(mc
->max
)) - 1;
223 template.shift
= mc
->shift
;
225 template.off_val
= mc
->max
;
227 template.off_val
= 0;
228 template.on_val
= template.off_val
;
229 template.id
= snd_soc_dapm_kcontrol
;
230 template.name
= kcontrol
->id
.name
;
232 data
->value
= template.on_val
;
234 data
->widget
= snd_soc_dapm_new_control(widget
->dapm
,
246 kcontrol
->private_data
= data
;
251 static void dapm_kcontrol_free(struct snd_kcontrol
*kctl
)
253 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kctl
);
259 static struct snd_soc_dapm_widget_list
*dapm_kcontrol_get_wlist(
260 const struct snd_kcontrol
*kcontrol
)
262 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
267 static int dapm_kcontrol_add_widget(struct snd_kcontrol
*kcontrol
,
268 struct snd_soc_dapm_widget
*widget
)
270 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
271 struct snd_soc_dapm_widget_list
*new_wlist
;
275 n
= data
->wlist
->num_widgets
+ 1;
279 new_wlist
= krealloc(data
->wlist
,
280 sizeof(*new_wlist
) + sizeof(widget
) * n
, GFP_KERNEL
);
284 new_wlist
->widgets
[n
- 1] = widget
;
285 new_wlist
->num_widgets
= n
;
287 data
->wlist
= new_wlist
;
292 static void dapm_kcontrol_add_path(const struct snd_kcontrol
*kcontrol
,
293 struct snd_soc_dapm_path
*path
)
295 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
297 list_add_tail(&path
->list_kcontrol
, &data
->paths
);
300 snd_soc_dapm_add_path(data
->widget
->dapm
, data
->widget
,
301 path
->source
, NULL
, NULL
);
305 static bool dapm_kcontrol_is_powered(const struct snd_kcontrol
*kcontrol
)
307 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
312 return data
->widget
->power
;
315 static struct list_head
*dapm_kcontrol_get_path_list(
316 const struct snd_kcontrol
*kcontrol
)
318 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
323 #define dapm_kcontrol_for_each_path(path, kcontrol) \
324 list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
327 static unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol
*kcontrol
)
329 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
334 static bool dapm_kcontrol_set_value(const struct snd_kcontrol
*kcontrol
,
337 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
339 if (data
->value
== value
)
343 data
->widget
->on_val
= value
;
351 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
352 * @kcontrol: The kcontrol
354 struct snd_soc_codec
*snd_soc_dapm_kcontrol_codec(struct snd_kcontrol
*kcontrol
)
356 return dapm_kcontrol_get_wlist(kcontrol
)->widgets
[0]->codec
;
358 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_codec
);
360 static void dapm_reset(struct snd_soc_card
*card
)
362 struct snd_soc_dapm_widget
*w
;
364 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
366 list_for_each_entry(w
, &card
->widgets
, list
) {
367 w
->new_power
= w
->power
;
368 w
->power_checked
= false;
374 static int soc_widget_read(struct snd_soc_dapm_widget
*w
, int reg
,
378 *value
= snd_soc_read(w
->codec
, reg
);
380 } else if (w
->platform
) {
381 *value
= snd_soc_platform_read(w
->platform
, reg
);
385 dev_err(w
->dapm
->dev
, "ASoC: no valid widget read method\n");
389 static int soc_widget_write(struct snd_soc_dapm_widget
*w
, int reg
,
393 return snd_soc_write(w
->codec
, reg
, val
);
394 else if (w
->platform
)
395 return snd_soc_platform_write(w
->platform
, reg
, val
);
397 dev_err(w
->dapm
->dev
, "ASoC: no valid widget write method\n");
401 static inline void soc_widget_lock(struct snd_soc_dapm_widget
*w
)
403 if (w
->codec
&& !w
->codec
->using_regmap
)
404 mutex_lock(&w
->codec
->mutex
);
405 else if (w
->platform
)
406 mutex_lock(&w
->platform
->mutex
);
409 static inline void soc_widget_unlock(struct snd_soc_dapm_widget
*w
)
411 if (w
->codec
&& !w
->codec
->using_regmap
)
412 mutex_unlock(&w
->codec
->mutex
);
413 else if (w
->platform
)
414 mutex_unlock(&w
->platform
->mutex
);
417 static void soc_dapm_async_complete(struct snd_soc_dapm_context
*dapm
)
419 if (dapm
->codec
&& dapm
->codec
->using_regmap
)
420 regmap_async_complete(dapm
->codec
->control_data
);
423 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget
*w
,
424 unsigned short reg
, unsigned int mask
, unsigned int value
)
427 unsigned int old
, new;
430 if (w
->codec
&& w
->codec
->using_regmap
) {
431 ret
= regmap_update_bits_check_async(w
->codec
->control_data
,
438 ret
= soc_widget_read(w
, reg
, &old
);
440 soc_widget_unlock(w
);
444 new = (old
& ~mask
) | (value
& mask
);
447 ret
= soc_widget_write(w
, reg
, new);
449 soc_widget_unlock(w
);
453 soc_widget_unlock(w
);
460 * snd_soc_dapm_set_bias_level - set the bias level for the system
461 * @dapm: DAPM context
462 * @level: level to configure
464 * Configure the bias (power) levels for the SoC audio device.
466 * Returns 0 for success else error.
468 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
469 enum snd_soc_bias_level level
)
471 struct snd_soc_card
*card
= dapm
->card
;
474 trace_snd_soc_bias_level_start(card
, level
);
476 if (card
&& card
->set_bias_level
)
477 ret
= card
->set_bias_level(card
, dapm
, level
);
482 if (dapm
->codec
->driver
->set_bias_level
)
483 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
486 dapm
->bias_level
= level
;
487 } else if (!card
|| dapm
!= &card
->dapm
) {
488 dapm
->bias_level
= level
;
494 if (card
&& card
->set_bias_level_post
)
495 ret
= card
->set_bias_level_post(card
, dapm
, level
);
497 trace_snd_soc_bias_level_done(card
, level
);
502 /* set up initial codec paths */
503 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
504 struct snd_soc_dapm_path
*p
, int i
)
507 case snd_soc_dapm_switch
:
508 case snd_soc_dapm_mixer
:
509 case snd_soc_dapm_mixer_named_ctl
: {
511 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
512 w
->kcontrol_news
[i
].private_value
;
514 unsigned int shift
= mc
->shift
;
516 unsigned int mask
= (1 << fls(max
)) - 1;
517 unsigned int invert
= mc
->invert
;
519 if (reg
!= SND_SOC_NOPM
) {
520 soc_widget_read(w
, reg
, &val
);
521 val
= (val
>> shift
) & mask
;
531 case snd_soc_dapm_mux
: {
532 struct soc_enum
*e
= (struct soc_enum
*)
533 w
->kcontrol_news
[i
].private_value
;
534 unsigned int val
, item
;
536 soc_widget_read(w
, e
->reg
, &val
);
537 item
= (val
>> e
->shift_l
) & e
->mask
;
539 if (item
< e
->max
&& !strcmp(p
->name
, e
->texts
[item
]))
545 case snd_soc_dapm_virt_mux
: {
546 struct soc_enum
*e
= (struct soc_enum
*)
547 w
->kcontrol_news
[i
].private_value
;
550 /* since a virtual mux has no backing registers to
551 * decide which path to connect, it will try to match
552 * with the first enumeration. This is to ensure
553 * that the default mux choice (the first) will be
554 * correctly powered up during initialization.
556 if (!strcmp(p
->name
, e
->texts
[0]))
560 case snd_soc_dapm_value_mux
: {
561 struct soc_enum
*e
= (struct soc_enum
*)
562 w
->kcontrol_news
[i
].private_value
;
563 unsigned int val
, item
;
565 soc_widget_read(w
, e
->reg
, &val
);
566 val
= (val
>> e
->shift_l
) & e
->mask
;
567 for (item
= 0; item
< e
->max
; item
++) {
568 if (val
== e
->values
[item
])
572 if (item
< e
->max
&& !strcmp(p
->name
, e
->texts
[item
]))
578 /* does not affect routing - always connected */
579 case snd_soc_dapm_pga
:
580 case snd_soc_dapm_out_drv
:
581 case snd_soc_dapm_output
:
582 case snd_soc_dapm_adc
:
583 case snd_soc_dapm_input
:
584 case snd_soc_dapm_siggen
:
585 case snd_soc_dapm_dac
:
586 case snd_soc_dapm_micbias
:
587 case snd_soc_dapm_vmid
:
588 case snd_soc_dapm_supply
:
589 case snd_soc_dapm_regulator_supply
:
590 case snd_soc_dapm_clock_supply
:
591 case snd_soc_dapm_aif_in
:
592 case snd_soc_dapm_aif_out
:
593 case snd_soc_dapm_dai_in
:
594 case snd_soc_dapm_dai_out
:
595 case snd_soc_dapm_hp
:
596 case snd_soc_dapm_mic
:
597 case snd_soc_dapm_spk
:
598 case snd_soc_dapm_line
:
599 case snd_soc_dapm_dai_link
:
600 case snd_soc_dapm_kcontrol
:
603 /* does affect routing - dynamically connected */
604 case snd_soc_dapm_pre
:
605 case snd_soc_dapm_post
:
611 /* connect mux widget to its interconnecting audio paths */
612 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
613 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
614 struct snd_soc_dapm_path
*path
, const char *control_name
,
615 const struct snd_kcontrol_new
*kcontrol
)
617 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
620 for (i
= 0; i
< e
->max
; i
++) {
621 if (!(strcmp(control_name
, e
->texts
[i
]))) {
622 list_add(&path
->list
, &dapm
->card
->paths
);
623 list_add(&path
->list_sink
, &dest
->sources
);
624 list_add(&path
->list_source
, &src
->sinks
);
625 path
->name
= (char*)e
->texts
[i
];
626 dapm_set_path_status(dest
, path
, 0);
634 /* connect mixer widget to its interconnecting audio paths */
635 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
636 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
637 struct snd_soc_dapm_path
*path
, const char *control_name
)
641 /* search for mixer kcontrol */
642 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
643 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
644 list_add(&path
->list
, &dapm
->card
->paths
);
645 list_add(&path
->list_sink
, &dest
->sources
);
646 list_add(&path
->list_source
, &src
->sinks
);
647 path
->name
= dest
->kcontrol_news
[i
].name
;
648 dapm_set_path_status(dest
, path
, i
);
655 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
656 struct snd_soc_dapm_widget
*kcontrolw
,
657 const struct snd_kcontrol_new
*kcontrol_new
,
658 struct snd_kcontrol
**kcontrol
)
660 struct snd_soc_dapm_widget
*w
;
665 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
666 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
668 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
669 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
671 *kcontrol
= w
->kcontrols
[i
];
681 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
682 * create it. Either way, add the widget into the control's widget list
684 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget
*w
,
687 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
688 struct snd_card
*card
= dapm
->card
->snd_card
;
692 struct snd_kcontrol
*kcontrol
;
693 bool wname_in_long_name
, kcname_in_long_name
;
699 prefix
= dapm
->codec
->name_prefix
;
704 prefix_len
= strlen(prefix
) + 1;
708 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
713 wname_in_long_name
= false;
714 kcname_in_long_name
= true;
717 case snd_soc_dapm_switch
:
718 case snd_soc_dapm_mixer
:
719 wname_in_long_name
= true;
720 kcname_in_long_name
= true;
722 case snd_soc_dapm_mixer_named_ctl
:
723 wname_in_long_name
= false;
724 kcname_in_long_name
= true;
726 case snd_soc_dapm_mux
:
727 case snd_soc_dapm_virt_mux
:
728 case snd_soc_dapm_value_mux
:
729 wname_in_long_name
= true;
730 kcname_in_long_name
= false;
737 if (wname_in_long_name
&& kcname_in_long_name
) {
739 * The control will get a prefix from the control
740 * creation process but we're also using the same
741 * prefix for widgets so cut the prefix off the
742 * front of the widget name.
744 long_name
= kasprintf(GFP_KERNEL
, "%s %s",
745 w
->name
+ prefix_len
,
746 w
->kcontrol_news
[kci
].name
);
747 if (long_name
== NULL
)
751 } else if (wname_in_long_name
) {
753 name
= w
->name
+ prefix_len
;
756 name
= w
->kcontrol_news
[kci
].name
;
759 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], NULL
, name
,
764 kcontrol
->private_free
= dapm_kcontrol_free
;
766 ret
= dapm_kcontrol_data_alloc(w
, kcontrol
);
768 snd_ctl_free_one(kcontrol
);
772 ret
= snd_ctl_add(card
, kcontrol
);
775 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
781 ret
= dapm_kcontrol_add_widget(kcontrol
, w
);
785 w
->kcontrols
[kci
] = kcontrol
;
790 /* create new dapm mixer control */
791 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
794 struct snd_soc_dapm_path
*path
;
797 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
799 list_for_each_entry(path
, &w
->sources
, list_sink
) {
800 /* mixer/mux paths name must match control name */
801 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
804 if (w
->kcontrols
[i
]) {
805 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
809 ret
= dapm_create_or_share_mixmux_kcontrol(w
, i
);
813 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
820 /* create new dapm mux control */
821 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
823 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
824 struct snd_soc_dapm_path
*path
;
827 if (w
->num_kcontrols
!= 1) {
829 "ASoC: mux %s has incorrect number of controls\n",
834 if (list_empty(&w
->sources
)) {
835 dev_err(dapm
->dev
, "ASoC: mux %s has no paths\n", w
->name
);
839 ret
= dapm_create_or_share_mixmux_kcontrol(w
, 0);
843 list_for_each_entry(path
, &w
->sources
, list_sink
)
844 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
849 /* create new dapm volume control */
850 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
852 if (w
->num_kcontrols
)
853 dev_err(w
->dapm
->dev
,
854 "ASoC: PGA controls not supported: '%s'\n", w
->name
);
859 /* reset 'walked' bit for each dapm path */
860 static void dapm_clear_walk_output(struct snd_soc_dapm_context
*dapm
,
861 struct list_head
*sink
)
863 struct snd_soc_dapm_path
*p
;
865 list_for_each_entry(p
, sink
, list_source
) {
868 dapm_clear_walk_output(dapm
, &p
->sink
->sinks
);
873 static void dapm_clear_walk_input(struct snd_soc_dapm_context
*dapm
,
874 struct list_head
*source
)
876 struct snd_soc_dapm_path
*p
;
878 list_for_each_entry(p
, source
, list_sink
) {
881 dapm_clear_walk_input(dapm
, &p
->source
->sources
);
887 /* We implement power down on suspend by checking the power state of
888 * the ALSA card - when we are suspending the ALSA state for the card
891 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
893 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
896 case SNDRV_CTL_POWER_D3hot
:
897 case SNDRV_CTL_POWER_D3cold
:
898 if (widget
->ignore_suspend
)
899 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
901 return widget
->ignore_suspend
;
907 /* add widget to list if it's not already in the list */
908 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
909 struct snd_soc_dapm_widget
*w
)
911 struct snd_soc_dapm_widget_list
*wlist
;
912 int wlistsize
, wlistentries
, i
;
919 /* is this widget already in the list */
920 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
921 if (wlist
->widgets
[i
] == w
)
925 /* allocate some new space */
926 wlistentries
= wlist
->num_widgets
+ 1;
927 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
928 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
929 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
931 dev_err(w
->dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
937 /* insert the widget */
938 dev_dbg(w
->dapm
->dev
, "ASoC: added %s in widget list pos %d\n",
939 w
->name
, wlist
->num_widgets
);
941 wlist
->widgets
[wlist
->num_widgets
] = w
;
942 wlist
->num_widgets
++;
947 * Recursively check for a completed path to an active or physically connected
948 * output widget. Returns number of complete paths.
950 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
951 struct snd_soc_dapm_widget_list
**list
)
953 struct snd_soc_dapm_path
*path
;
956 if (widget
->outputs
>= 0)
957 return widget
->outputs
;
959 DAPM_UPDATE_STAT(widget
, path_checks
);
961 switch (widget
->id
) {
962 case snd_soc_dapm_supply
:
963 case snd_soc_dapm_regulator_supply
:
964 case snd_soc_dapm_clock_supply
:
965 case snd_soc_dapm_kcontrol
:
971 switch (widget
->id
) {
972 case snd_soc_dapm_adc
:
973 case snd_soc_dapm_aif_out
:
974 case snd_soc_dapm_dai_out
:
975 if (widget
->active
) {
976 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
977 return widget
->outputs
;
983 if (widget
->connected
) {
984 /* connected pin ? */
985 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
986 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
987 return widget
->outputs
;
990 /* connected jack or spk ? */
991 if (widget
->id
== snd_soc_dapm_hp
||
992 widget
->id
== snd_soc_dapm_spk
||
993 (widget
->id
== snd_soc_dapm_line
&&
994 !list_empty(&widget
->sources
))) {
995 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
996 return widget
->outputs
;
1000 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
1001 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1012 trace_snd_soc_dapm_output_path(widget
, path
);
1014 if (path
->sink
&& path
->connect
) {
1018 /* do we need to add this widget to the list ? */
1021 err
= dapm_list_add_widget(list
, path
->sink
);
1023 dev_err(widget
->dapm
->dev
,
1024 "ASoC: could not add widget %s\n",
1031 con
+= is_connected_output_ep(path
->sink
, list
);
1037 widget
->outputs
= con
;
1043 * Recursively check for a completed path to an active or physically connected
1044 * input widget. Returns number of complete paths.
1046 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
1047 struct snd_soc_dapm_widget_list
**list
)
1049 struct snd_soc_dapm_path
*path
;
1052 if (widget
->inputs
>= 0)
1053 return widget
->inputs
;
1055 DAPM_UPDATE_STAT(widget
, path_checks
);
1057 switch (widget
->id
) {
1058 case snd_soc_dapm_supply
:
1059 case snd_soc_dapm_regulator_supply
:
1060 case snd_soc_dapm_clock_supply
:
1061 case snd_soc_dapm_kcontrol
:
1067 /* active stream ? */
1068 switch (widget
->id
) {
1069 case snd_soc_dapm_dac
:
1070 case snd_soc_dapm_aif_in
:
1071 case snd_soc_dapm_dai_in
:
1072 if (widget
->active
) {
1073 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1074 return widget
->inputs
;
1080 if (widget
->connected
) {
1081 /* connected pin ? */
1082 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
1083 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1084 return widget
->inputs
;
1087 /* connected VMID/Bias for lower pops */
1088 if (widget
->id
== snd_soc_dapm_vmid
) {
1089 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1090 return widget
->inputs
;
1093 /* connected jack ? */
1094 if (widget
->id
== snd_soc_dapm_mic
||
1095 (widget
->id
== snd_soc_dapm_line
&&
1096 !list_empty(&widget
->sinks
))) {
1097 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1098 return widget
->inputs
;
1101 /* signal generator */
1102 if (widget
->id
== snd_soc_dapm_siggen
) {
1103 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1104 return widget
->inputs
;
1108 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
1109 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1120 trace_snd_soc_dapm_input_path(widget
, path
);
1122 if (path
->source
&& path
->connect
) {
1126 /* do we need to add this widget to the list ? */
1129 err
= dapm_list_add_widget(list
, path
->source
);
1131 dev_err(widget
->dapm
->dev
,
1132 "ASoC: could not add widget %s\n",
1139 con
+= is_connected_input_ep(path
->source
, list
);
1145 widget
->inputs
= con
;
1151 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1152 * @dai: the soc DAI.
1153 * @stream: stream direction.
1154 * @list: list of active widgets for this stream.
1156 * Queries DAPM graph as to whether an valid audio stream path exists for
1157 * the initial stream specified by name. This takes into account
1158 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1160 * Returns the number of valid paths or negative error.
1162 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1163 struct snd_soc_dapm_widget_list
**list
)
1165 struct snd_soc_card
*card
= dai
->card
;
1168 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1171 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1172 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
1173 dapm_clear_walk_output(&card
->dapm
,
1174 &dai
->playback_widget
->sinks
);
1176 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
1177 dapm_clear_walk_input(&card
->dapm
,
1178 &dai
->capture_widget
->sources
);
1181 trace_snd_soc_dapm_connected(paths
, stream
);
1182 mutex_unlock(&card
->dapm_mutex
);
1188 * Handler for generic register modifier widget.
1190 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
1191 struct snd_kcontrol
*kcontrol
, int event
)
1195 if (SND_SOC_DAPM_EVENT_ON(event
))
1200 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
1201 w
->mask
<< w
->shift
, val
<< w
->shift
);
1205 EXPORT_SYMBOL_GPL(dapm_reg_event
);
1208 * Handler for regulator supply widget.
1210 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1211 struct snd_kcontrol
*kcontrol
, int event
)
1215 soc_dapm_async_complete(w
->dapm
);
1217 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1218 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1219 ret
= regulator_allow_bypass(w
->regulator
, false);
1221 dev_warn(w
->dapm
->dev
,
1222 "ASoC: Failed to unbypass %s: %d\n",
1226 return regulator_enable(w
->regulator
);
1228 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1229 ret
= regulator_allow_bypass(w
->regulator
, true);
1231 dev_warn(w
->dapm
->dev
,
1232 "ASoC: Failed to bypass %s: %d\n",
1236 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1239 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1242 * Handler for clock supply widget.
1244 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1245 struct snd_kcontrol
*kcontrol
, int event
)
1250 soc_dapm_async_complete(w
->dapm
);
1252 #ifdef CONFIG_HAVE_CLK
1253 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1254 return clk_prepare_enable(w
->clk
);
1256 clk_disable_unprepare(w
->clk
);
1262 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1264 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1266 if (w
->power_checked
)
1267 return w
->new_power
;
1272 w
->new_power
= w
->power_check(w
);
1274 w
->power_checked
= true;
1276 return w
->new_power
;
1279 /* Generic check to see if a widget should be powered.
1281 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1285 DAPM_UPDATE_STAT(w
, power_checks
);
1287 in
= is_connected_input_ep(w
, NULL
);
1288 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1289 out
= is_connected_output_ep(w
, NULL
);
1290 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1291 return out
!= 0 && in
!= 0;
1294 /* Check to see if an ADC has power */
1295 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
1299 DAPM_UPDATE_STAT(w
, power_checks
);
1302 in
= is_connected_input_ep(w
, NULL
);
1303 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1306 return dapm_generic_check_power(w
);
1310 /* Check to see if a DAC has power */
1311 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
1315 DAPM_UPDATE_STAT(w
, power_checks
);
1318 out
= is_connected_output_ep(w
, NULL
);
1319 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1322 return dapm_generic_check_power(w
);
1326 /* Check to see if a power supply is needed */
1327 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1329 struct snd_soc_dapm_path
*path
;
1331 DAPM_UPDATE_STAT(w
, power_checks
);
1333 /* Check if one of our outputs is connected */
1334 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1335 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1340 if (path
->connected
&&
1341 !path
->connected(path
->source
, path
->sink
))
1347 if (dapm_widget_power_check(path
->sink
))
1354 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1359 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1360 struct snd_soc_dapm_widget
*b
,
1368 sort
= dapm_down_seq
;
1370 if (sort
[a
->id
] != sort
[b
->id
])
1371 return sort
[a
->id
] - sort
[b
->id
];
1372 if (a
->subseq
!= b
->subseq
) {
1374 return a
->subseq
- b
->subseq
;
1376 return b
->subseq
- a
->subseq
;
1378 if (a
->reg
!= b
->reg
)
1379 return a
->reg
- b
->reg
;
1380 if (a
->dapm
!= b
->dapm
)
1381 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1386 /* Insert a widget in order into a DAPM power sequence. */
1387 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1388 struct list_head
*list
,
1391 struct snd_soc_dapm_widget
*w
;
1393 list_for_each_entry(w
, list
, power_list
)
1394 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1395 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1399 list_add_tail(&new_widget
->power_list
, list
);
1402 static void dapm_seq_check_event(struct snd_soc_card
*card
,
1403 struct snd_soc_dapm_widget
*w
, int event
)
1405 const char *ev_name
;
1409 case SND_SOC_DAPM_PRE_PMU
:
1410 ev_name
= "PRE_PMU";
1413 case SND_SOC_DAPM_POST_PMU
:
1414 ev_name
= "POST_PMU";
1417 case SND_SOC_DAPM_PRE_PMD
:
1418 ev_name
= "PRE_PMD";
1421 case SND_SOC_DAPM_POST_PMD
:
1422 ev_name
= "POST_PMD";
1425 case SND_SOC_DAPM_WILL_PMU
:
1426 ev_name
= "WILL_PMU";
1429 case SND_SOC_DAPM_WILL_PMD
:
1430 ev_name
= "WILL_PMD";
1434 WARN(1, "Unknown event %d\n", event
);
1438 if (w
->new_power
!= power
)
1441 if (w
->event
&& (w
->event_flags
& event
)) {
1442 pop_dbg(w
->dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1444 soc_dapm_async_complete(w
->dapm
);
1445 trace_snd_soc_dapm_widget_event_start(w
, event
);
1446 ret
= w
->event(w
, NULL
, event
);
1447 trace_snd_soc_dapm_widget_event_done(w
, event
);
1449 dev_err(w
->dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1450 ev_name
, w
->name
, ret
);
1454 /* Apply the coalesced changes from a DAPM sequence */
1455 static void dapm_seq_run_coalesced(struct snd_soc_card
*card
,
1456 struct list_head
*pending
)
1458 struct snd_soc_dapm_widget
*w
;
1460 unsigned int value
= 0;
1461 unsigned int mask
= 0;
1463 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1466 list_for_each_entry(w
, pending
, power_list
) {
1467 WARN_ON(reg
!= w
->reg
);
1468 w
->power
= w
->new_power
;
1470 mask
|= w
->mask
<< w
->shift
;
1472 value
|= w
->on_val
<< w
->shift
;
1474 value
|= w
->off_val
<< w
->shift
;
1476 pop_dbg(w
->dapm
->dev
, card
->pop_time
,
1477 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1478 w
->name
, reg
, value
, mask
);
1480 /* Check for events */
1481 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMU
);
1482 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMD
);
1486 /* Any widget will do, they should all be updating the
1489 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1492 pop_dbg(w
->dapm
->dev
, card
->pop_time
,
1493 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1494 value
, mask
, reg
, card
->pop_time
);
1495 pop_wait(card
->pop_time
);
1496 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1499 list_for_each_entry(w
, pending
, power_list
) {
1500 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMU
);
1501 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMD
);
1505 /* Apply a DAPM power sequence.
1507 * We walk over a pre-sorted list of widgets to apply power to. In
1508 * order to minimise the number of writes to the device required
1509 * multiple widgets will be updated in a single write where possible.
1510 * Currently anything that requires more than a single write is not
1513 static void dapm_seq_run(struct snd_soc_card
*card
,
1514 struct list_head
*list
, int event
, bool power_up
)
1516 struct snd_soc_dapm_widget
*w
, *n
;
1517 struct snd_soc_dapm_context
*d
;
1520 int cur_subseq
= -1;
1521 int cur_reg
= SND_SOC_NOPM
;
1522 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1529 sort
= dapm_down_seq
;
1531 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1534 /* Do we need to apply any queued changes? */
1535 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1536 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1537 if (!list_empty(&pending
))
1538 dapm_seq_run_coalesced(card
, &pending
);
1540 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1541 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1542 if (sort
[i
] == cur_sort
)
1543 cur_dapm
->seq_notifier(cur_dapm
,
1548 if (cur_dapm
&& w
->dapm
!= cur_dapm
)
1549 soc_dapm_async_complete(cur_dapm
);
1551 INIT_LIST_HEAD(&pending
);
1553 cur_subseq
= INT_MIN
;
1554 cur_reg
= SND_SOC_NOPM
;
1559 case snd_soc_dapm_pre
:
1561 list_for_each_entry_safe_continue(w
, n
, list
,
1564 if (event
== SND_SOC_DAPM_STREAM_START
)
1566 NULL
, SND_SOC_DAPM_PRE_PMU
);
1567 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1569 NULL
, SND_SOC_DAPM_PRE_PMD
);
1572 case snd_soc_dapm_post
:
1574 list_for_each_entry_safe_continue(w
, n
, list
,
1577 if (event
== SND_SOC_DAPM_STREAM_START
)
1579 NULL
, SND_SOC_DAPM_POST_PMU
);
1580 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1582 NULL
, SND_SOC_DAPM_POST_PMD
);
1586 /* Queue it up for application */
1587 cur_sort
= sort
[w
->id
];
1588 cur_subseq
= w
->subseq
;
1591 list_move(&w
->power_list
, &pending
);
1596 dev_err(w
->dapm
->dev
,
1597 "ASoC: Failed to apply widget power: %d\n", ret
);
1600 if (!list_empty(&pending
))
1601 dapm_seq_run_coalesced(card
, &pending
);
1603 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1604 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1605 if (sort
[i
] == cur_sort
)
1606 cur_dapm
->seq_notifier(cur_dapm
,
1610 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1611 soc_dapm_async_complete(d
);
1615 static void dapm_widget_update(struct snd_soc_card
*card
)
1617 struct snd_soc_dapm_update
*update
= card
->update
;
1618 struct snd_soc_dapm_widget_list
*wlist
;
1619 struct snd_soc_dapm_widget
*w
= NULL
;
1623 if (!update
|| !dapm_kcontrol_is_powered(update
->kcontrol
))
1626 wlist
= dapm_kcontrol_get_wlist(update
->kcontrol
);
1628 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1629 w
= wlist
->widgets
[wi
];
1631 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1632 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1634 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1642 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1645 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1648 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1649 w
= wlist
->widgets
[wi
];
1651 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1652 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1654 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1660 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1661 * they're changing state.
1663 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1665 struct snd_soc_dapm_context
*d
= data
;
1668 /* If we're off and we're not supposed to be go into STANDBY */
1669 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1670 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1672 pm_runtime_get_sync(d
->dev
);
1674 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1677 "ASoC: Failed to turn on bias: %d\n", ret
);
1680 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1681 if (d
->bias_level
!= d
->target_bias_level
) {
1682 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1685 "ASoC: Failed to prepare bias: %d\n", ret
);
1689 /* Async callback run prior to DAPM sequences - brings to their final
1692 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1694 struct snd_soc_dapm_context
*d
= data
;
1697 /* If we just powered the last thing off drop to standby bias */
1698 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1699 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1700 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1701 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1703 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1707 /* If we're in standby and can support bias off then do that */
1708 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1709 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1710 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1712 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1716 pm_runtime_put(d
->dev
);
1719 /* If we just powered up then move to active bias */
1720 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1721 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1722 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1724 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1729 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1730 bool power
, bool connect
)
1732 /* If a connection is being made or broken then that update
1733 * will have marked the peer dirty, otherwise the widgets are
1734 * not connected and this update has no impact. */
1738 /* If the peer is already in the state we're moving to then we
1739 * won't have an impact on it. */
1740 if (power
!= peer
->power
)
1741 dapm_mark_dirty(peer
, "peer state change");
1744 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1745 struct list_head
*up_list
,
1746 struct list_head
*down_list
)
1748 struct snd_soc_dapm_path
*path
;
1750 if (w
->power
== power
)
1753 trace_snd_soc_dapm_widget_power(w
, power
);
1755 /* If we changed our power state perhaps our neigbours changed
1758 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1760 dapm_widget_set_peer_power(path
->source
, power
,
1765 case snd_soc_dapm_supply
:
1766 case snd_soc_dapm_regulator_supply
:
1767 case snd_soc_dapm_clock_supply
:
1768 case snd_soc_dapm_kcontrol
:
1769 /* Supplies can't affect their outputs, only their inputs */
1772 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1774 dapm_widget_set_peer_power(path
->sink
, power
,
1782 dapm_seq_insert(w
, up_list
, true);
1784 dapm_seq_insert(w
, down_list
, false);
1787 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1788 struct list_head
*up_list
,
1789 struct list_head
*down_list
)
1794 case snd_soc_dapm_pre
:
1795 dapm_seq_insert(w
, down_list
, false);
1797 case snd_soc_dapm_post
:
1798 dapm_seq_insert(w
, up_list
, true);
1802 power
= dapm_widget_power_check(w
);
1804 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1810 * Scan each dapm widget for complete audio path.
1811 * A complete path is a route that has valid endpoints i.e.:-
1813 * o DAC to output pin.
1814 * o Input Pin to ADC.
1815 * o Input pin to Output pin (bypass, sidetone)
1816 * o DAC to ADC (loopback).
1818 static int dapm_power_widgets(struct snd_soc_card
*card
, int event
)
1820 struct snd_soc_dapm_widget
*w
;
1821 struct snd_soc_dapm_context
*d
;
1823 LIST_HEAD(down_list
);
1824 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1825 enum snd_soc_bias_level bias
;
1827 trace_snd_soc_dapm_start(card
);
1829 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1830 if (d
->idle_bias_off
)
1831 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1833 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1838 /* Check which widgets we need to power and store them in
1839 * lists indicating if they should be powered up or down. We
1840 * only check widgets that have been flagged as dirty but note
1841 * that new widgets may be added to the dirty list while we
1844 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1845 dapm_power_one_widget(w
, &up_list
, &down_list
);
1848 list_for_each_entry(w
, &card
->widgets
, list
) {
1850 case snd_soc_dapm_pre
:
1851 case snd_soc_dapm_post
:
1852 /* These widgets always need to be powered */
1855 list_del_init(&w
->dirty
);
1862 /* Supplies and micbiases only bring the
1863 * context up to STANDBY as unless something
1864 * else is active and passing audio they
1865 * generally don't require full power. Signal
1866 * generators are virtual pins and have no
1867 * power impact themselves.
1870 case snd_soc_dapm_siggen
:
1871 case snd_soc_dapm_vmid
:
1873 case snd_soc_dapm_supply
:
1874 case snd_soc_dapm_regulator_supply
:
1875 case snd_soc_dapm_clock_supply
:
1876 case snd_soc_dapm_micbias
:
1877 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1878 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1881 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1888 /* Force all contexts in the card to the same bias state if
1889 * they're not ground referenced.
1891 bias
= SND_SOC_BIAS_OFF
;
1892 list_for_each_entry(d
, &card
->dapm_list
, list
)
1893 if (d
->target_bias_level
> bias
)
1894 bias
= d
->target_bias_level
;
1895 list_for_each_entry(d
, &card
->dapm_list
, list
)
1896 if (!d
->idle_bias_off
)
1897 d
->target_bias_level
= bias
;
1899 trace_snd_soc_dapm_walk_done(card
);
1901 /* Run all the bias changes in parallel */
1902 list_for_each_entry(d
, &card
->dapm_list
, list
)
1903 async_schedule_domain(dapm_pre_sequence_async
, d
,
1905 async_synchronize_full_domain(&async_domain
);
1907 list_for_each_entry(w
, &down_list
, power_list
) {
1908 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMD
);
1911 list_for_each_entry(w
, &up_list
, power_list
) {
1912 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMU
);
1915 /* Power down widgets first; try to avoid amplifying pops. */
1916 dapm_seq_run(card
, &down_list
, event
, false);
1918 dapm_widget_update(card
);
1921 dapm_seq_run(card
, &up_list
, event
, true);
1923 /* Run all the bias changes in parallel */
1924 list_for_each_entry(d
, &card
->dapm_list
, list
)
1925 async_schedule_domain(dapm_post_sequence_async
, d
,
1927 async_synchronize_full_domain(&async_domain
);
1929 /* do we need to notify any clients that DAPM event is complete */
1930 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1931 if (d
->stream_event
)
1932 d
->stream_event(d
, event
);
1935 pop_dbg(card
->dev
, card
->pop_time
,
1936 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1937 pop_wait(card
->pop_time
);
1939 trace_snd_soc_dapm_done(card
);
1944 #ifdef CONFIG_DEBUG_FS
1945 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1946 char __user
*user_buf
,
1947 size_t count
, loff_t
*ppos
)
1949 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1953 struct snd_soc_dapm_path
*p
= NULL
;
1955 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1959 in
= is_connected_input_ep(w
, NULL
);
1960 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1961 out
= is_connected_output_ep(w
, NULL
);
1962 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1964 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1965 w
->name
, w
->power
? "On" : "Off",
1966 w
->force
? " (forced)" : "", in
, out
);
1969 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1970 " - R%d(0x%x) mask 0x%x",
1971 w
->reg
, w
->reg
, w
->mask
<< w
->shift
);
1973 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1976 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1978 w
->active
? "active" : "inactive");
1980 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1981 if (p
->connected
&& !p
->connected(w
, p
->source
))
1985 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1986 " in \"%s\" \"%s\"\n",
1987 p
->name
? p
->name
: "static",
1990 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1991 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1995 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1996 " out \"%s\" \"%s\"\n",
1997 p
->name
? p
->name
: "static",
2001 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
2007 static const struct file_operations dapm_widget_power_fops
= {
2008 .open
= simple_open
,
2009 .read
= dapm_widget_power_read_file
,
2010 .llseek
= default_llseek
,
2013 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
2014 size_t count
, loff_t
*ppos
)
2016 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
2019 switch (dapm
->bias_level
) {
2020 case SND_SOC_BIAS_ON
:
2023 case SND_SOC_BIAS_PREPARE
:
2024 level
= "Prepare\n";
2026 case SND_SOC_BIAS_STANDBY
:
2027 level
= "Standby\n";
2029 case SND_SOC_BIAS_OFF
:
2033 WARN(1, "Unknown bias_level %d\n", dapm
->bias_level
);
2034 level
= "Unknown\n";
2038 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
2042 static const struct file_operations dapm_bias_fops
= {
2043 .open
= simple_open
,
2044 .read
= dapm_bias_read_file
,
2045 .llseek
= default_llseek
,
2048 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2049 struct dentry
*parent
)
2053 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
2055 if (!dapm
->debugfs_dapm
) {
2057 "ASoC: Failed to create DAPM debugfs directory\n");
2061 d
= debugfs_create_file("bias_level", 0444,
2062 dapm
->debugfs_dapm
, dapm
,
2066 "ASoC: Failed to create bias level debugfs file\n");
2069 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2071 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
2074 if (!dapm
->debugfs_dapm
|| !w
->name
)
2077 d
= debugfs_create_file(w
->name
, 0444,
2078 dapm
->debugfs_dapm
, w
,
2079 &dapm_widget_power_fops
);
2081 dev_warn(w
->dapm
->dev
,
2082 "ASoC: Failed to create %s debugfs file\n",
2086 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2088 debugfs_remove_recursive(dapm
->debugfs_dapm
);
2092 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2093 struct dentry
*parent
)
2097 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2101 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2107 /* test and update the power status of a mux widget */
2108 static int soc_dapm_mux_update_power(struct snd_soc_card
*card
,
2109 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
2111 struct snd_soc_dapm_path
*path
;
2114 /* find dapm widget path assoc with kcontrol */
2115 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2116 if (!path
->name
|| !e
->texts
[mux
])
2120 /* we now need to match the string in the enum to the path */
2121 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
2122 path
->connect
= 1; /* new connection */
2123 dapm_mark_dirty(path
->source
, "mux connection");
2126 dapm_mark_dirty(path
->source
,
2127 "mux disconnection");
2128 path
->connect
= 0; /* old connection must be powered down */
2130 dapm_mark_dirty(path
->sink
, "mux change");
2134 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2139 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context
*dapm
,
2140 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
,
2141 struct snd_soc_dapm_update
*update
)
2143 struct snd_soc_card
*card
= dapm
->card
;
2146 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2147 card
->update
= update
;
2148 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
2149 card
->update
= NULL
;
2150 mutex_unlock(&card
->dapm_mutex
);
2152 soc_dpcm_runtime_update(card
);
2155 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
2157 /* test and update the power status of a mixer or switch widget */
2158 static int soc_dapm_mixer_update_power(struct snd_soc_card
*card
,
2159 struct snd_kcontrol
*kcontrol
, int connect
)
2161 struct snd_soc_dapm_path
*path
;
2164 /* find dapm widget path assoc with kcontrol */
2165 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2167 path
->connect
= connect
;
2168 dapm_mark_dirty(path
->source
, "mixer connection");
2169 dapm_mark_dirty(path
->sink
, "mixer update");
2173 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2178 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context
*dapm
,
2179 struct snd_kcontrol
*kcontrol
, int connect
,
2180 struct snd_soc_dapm_update
*update
)
2182 struct snd_soc_card
*card
= dapm
->card
;
2185 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2186 card
->update
= update
;
2187 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
2188 card
->update
= NULL
;
2189 mutex_unlock(&card
->dapm_mutex
);
2191 soc_dpcm_runtime_update(card
);
2194 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2196 /* show dapm widget status in sys fs */
2197 static ssize_t
dapm_widget_show(struct device
*dev
,
2198 struct device_attribute
*attr
, char *buf
)
2200 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2201 struct snd_soc_codec
*codec
=rtd
->codec
;
2202 struct snd_soc_dapm_widget
*w
;
2204 char *state
= "not set";
2206 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
2207 if (w
->dapm
!= &codec
->dapm
)
2210 /* only display widgets that burnm power */
2212 case snd_soc_dapm_hp
:
2213 case snd_soc_dapm_mic
:
2214 case snd_soc_dapm_spk
:
2215 case snd_soc_dapm_line
:
2216 case snd_soc_dapm_micbias
:
2217 case snd_soc_dapm_dac
:
2218 case snd_soc_dapm_adc
:
2219 case snd_soc_dapm_pga
:
2220 case snd_soc_dapm_out_drv
:
2221 case snd_soc_dapm_mixer
:
2222 case snd_soc_dapm_mixer_named_ctl
:
2223 case snd_soc_dapm_supply
:
2224 case snd_soc_dapm_regulator_supply
:
2225 case snd_soc_dapm_clock_supply
:
2227 count
+= sprintf(buf
+ count
, "%s: %s\n",
2228 w
->name
, w
->power
? "On":"Off");
2235 switch (codec
->dapm
.bias_level
) {
2236 case SND_SOC_BIAS_ON
:
2239 case SND_SOC_BIAS_PREPARE
:
2242 case SND_SOC_BIAS_STANDBY
:
2245 case SND_SOC_BIAS_OFF
:
2249 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2254 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2256 int snd_soc_dapm_sys_add(struct device
*dev
)
2258 return device_create_file(dev
, &dev_attr_dapm_widget
);
2261 static void snd_soc_dapm_sys_remove(struct device
*dev
)
2263 device_remove_file(dev
, &dev_attr_dapm_widget
);
2266 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2268 list_del(&path
->list_sink
);
2269 list_del(&path
->list_source
);
2270 list_del(&path
->list_kcontrol
);
2271 list_del(&path
->list
);
2275 /* free all dapm widgets and resources */
2276 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2278 struct snd_soc_dapm_widget
*w
, *next_w
;
2279 struct snd_soc_dapm_path
*p
, *next_p
;
2281 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2282 if (w
->dapm
!= dapm
)
2286 * remove source and sink paths associated to this widget.
2287 * While removing the path, remove reference to it from both
2288 * source and sink widgets so that path is removed only once.
2290 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
)
2293 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
)
2296 kfree(w
->kcontrols
);
2302 static struct snd_soc_dapm_widget
*dapm_find_widget(
2303 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2304 bool search_other_contexts
)
2306 struct snd_soc_dapm_widget
*w
;
2307 struct snd_soc_dapm_widget
*fallback
= NULL
;
2309 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2310 if (!strcmp(w
->name
, pin
)) {
2311 if (w
->dapm
== dapm
)
2318 if (search_other_contexts
)
2324 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2325 const char *pin
, int status
)
2327 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2330 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2334 if (w
->connected
!= status
)
2335 dapm_mark_dirty(w
, "pin configuration");
2337 w
->connected
= status
;
2345 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2346 * @dapm: DAPM context
2348 * Walks all dapm audio paths and powers widgets according to their
2349 * stream or path usage.
2351 * Requires external locking.
2353 * Returns 0 for success.
2355 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context
*dapm
)
2358 * Suppress early reports (eg, jacks syncing their state) to avoid
2359 * silly DAPM runs during card startup.
2361 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2364 return dapm_power_widgets(dapm
->card
, SND_SOC_DAPM_STREAM_NOP
);
2366 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked
);
2369 * snd_soc_dapm_sync - scan and power dapm paths
2370 * @dapm: DAPM context
2372 * Walks all dapm audio paths and powers widgets according to their
2373 * stream or path usage.
2375 * Returns 0 for success.
2377 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2381 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2382 ret
= snd_soc_dapm_sync_unlocked(dapm
);
2383 mutex_unlock(&dapm
->card
->dapm_mutex
);
2386 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2388 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
2389 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
2390 const char *control
,
2391 int (*connected
)(struct snd_soc_dapm_widget
*source
,
2392 struct snd_soc_dapm_widget
*sink
))
2394 struct snd_soc_dapm_path
*path
;
2397 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2401 path
->source
= wsource
;
2403 path
->connected
= connected
;
2404 INIT_LIST_HEAD(&path
->list
);
2405 INIT_LIST_HEAD(&path
->list_kcontrol
);
2406 INIT_LIST_HEAD(&path
->list_source
);
2407 INIT_LIST_HEAD(&path
->list_sink
);
2409 /* check for external widgets */
2410 if (wsink
->id
== snd_soc_dapm_input
) {
2411 if (wsource
->id
== snd_soc_dapm_micbias
||
2412 wsource
->id
== snd_soc_dapm_mic
||
2413 wsource
->id
== snd_soc_dapm_line
||
2414 wsource
->id
== snd_soc_dapm_output
)
2417 if (wsource
->id
== snd_soc_dapm_output
) {
2418 if (wsink
->id
== snd_soc_dapm_spk
||
2419 wsink
->id
== snd_soc_dapm_hp
||
2420 wsink
->id
== snd_soc_dapm_line
||
2421 wsink
->id
== snd_soc_dapm_input
)
2425 dapm_mark_dirty(wsource
, "Route added");
2426 dapm_mark_dirty(wsink
, "Route added");
2428 /* connect static paths */
2429 if (control
== NULL
) {
2430 list_add(&path
->list
, &dapm
->card
->paths
);
2431 list_add(&path
->list_sink
, &wsink
->sources
);
2432 list_add(&path
->list_source
, &wsource
->sinks
);
2437 /* connect dynamic paths */
2438 switch (wsink
->id
) {
2439 case snd_soc_dapm_adc
:
2440 case snd_soc_dapm_dac
:
2441 case snd_soc_dapm_pga
:
2442 case snd_soc_dapm_out_drv
:
2443 case snd_soc_dapm_input
:
2444 case snd_soc_dapm_output
:
2445 case snd_soc_dapm_siggen
:
2446 case snd_soc_dapm_micbias
:
2447 case snd_soc_dapm_vmid
:
2448 case snd_soc_dapm_pre
:
2449 case snd_soc_dapm_post
:
2450 case snd_soc_dapm_supply
:
2451 case snd_soc_dapm_regulator_supply
:
2452 case snd_soc_dapm_clock_supply
:
2453 case snd_soc_dapm_aif_in
:
2454 case snd_soc_dapm_aif_out
:
2455 case snd_soc_dapm_dai_in
:
2456 case snd_soc_dapm_dai_out
:
2457 case snd_soc_dapm_dai_link
:
2458 case snd_soc_dapm_kcontrol
:
2459 list_add(&path
->list
, &dapm
->card
->paths
);
2460 list_add(&path
->list_sink
, &wsink
->sources
);
2461 list_add(&path
->list_source
, &wsource
->sinks
);
2464 case snd_soc_dapm_mux
:
2465 case snd_soc_dapm_virt_mux
:
2466 case snd_soc_dapm_value_mux
:
2467 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2468 &wsink
->kcontrol_news
[0]);
2472 case snd_soc_dapm_switch
:
2473 case snd_soc_dapm_mixer
:
2474 case snd_soc_dapm_mixer_named_ctl
:
2475 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2479 case snd_soc_dapm_hp
:
2480 case snd_soc_dapm_mic
:
2481 case snd_soc_dapm_line
:
2482 case snd_soc_dapm_spk
:
2483 list_add(&path
->list
, &dapm
->card
->paths
);
2484 list_add(&path
->list_sink
, &wsink
->sources
);
2485 list_add(&path
->list_source
, &wsource
->sinks
);
2496 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2497 const struct snd_soc_dapm_route
*route
,
2498 unsigned int is_prefixed
)
2500 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2501 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2504 char prefixed_sink
[80];
2505 char prefixed_source
[80];
2508 if (dapm
->codec
&& dapm
->codec
->name_prefix
&& !is_prefixed
) {
2509 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2510 dapm
->codec
->name_prefix
, route
->sink
);
2511 sink
= prefixed_sink
;
2512 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2513 dapm
->codec
->name_prefix
, route
->source
);
2514 source
= prefixed_source
;
2517 source
= route
->source
;
2521 * find src and dest widgets over all widgets but favor a widget from
2522 * current DAPM context
2524 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2525 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2527 if (w
->dapm
== dapm
)
2531 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2533 if (w
->dapm
== dapm
)
2537 /* use widget from another DAPM context if not found from this */
2543 if (wsource
== NULL
) {
2544 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2548 if (wsink
== NULL
) {
2549 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2554 ret
= snd_soc_dapm_add_path(dapm
, wsource
, wsink
, route
->control
,
2561 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2562 source
, route
->control
, sink
);
2566 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2567 const struct snd_soc_dapm_route
*route
)
2569 struct snd_soc_dapm_path
*path
, *p
;
2572 char prefixed_sink
[80];
2573 char prefixed_source
[80];
2575 if (route
->control
) {
2577 "ASoC: Removal of routes with controls not supported\n");
2581 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2582 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2583 dapm
->codec
->name_prefix
, route
->sink
);
2584 sink
= prefixed_sink
;
2585 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2586 dapm
->codec
->name_prefix
, route
->source
);
2587 source
= prefixed_source
;
2590 source
= route
->source
;
2594 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2595 if (strcmp(p
->source
->name
, source
) != 0)
2597 if (strcmp(p
->sink
->name
, sink
) != 0)
2604 dapm_mark_dirty(path
->source
, "Route removed");
2605 dapm_mark_dirty(path
->sink
, "Route removed");
2607 dapm_free_path(path
);
2609 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
2617 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2618 * @dapm: DAPM context
2619 * @route: audio routes
2620 * @num: number of routes
2622 * Connects 2 dapm widgets together via a named audio path. The sink is
2623 * the widget receiving the audio signal, whilst the source is the sender
2624 * of the audio signal.
2626 * Returns 0 for success else error. On error all resources can be freed
2627 * with a call to snd_soc_card_free().
2629 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2630 const struct snd_soc_dapm_route
*route
, int num
)
2634 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2635 for (i
= 0; i
< num
; i
++) {
2636 r
= snd_soc_dapm_add_route(dapm
, route
, false);
2638 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
2640 route
->control
? route
->control
: "direct",
2646 mutex_unlock(&dapm
->card
->dapm_mutex
);
2650 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2653 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2654 * @dapm: DAPM context
2655 * @route: audio routes
2656 * @num: number of routes
2658 * Removes routes from the DAPM context.
2660 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2661 const struct snd_soc_dapm_route
*route
, int num
)
2665 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2666 for (i
= 0; i
< num
; i
++) {
2667 snd_soc_dapm_del_route(dapm
, route
);
2670 mutex_unlock(&dapm
->card
->dapm_mutex
);
2674 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2676 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2677 const struct snd_soc_dapm_route
*route
)
2679 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2682 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2685 struct snd_soc_dapm_path
*path
;
2689 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
2695 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
2700 if (route
->control
|| route
->connected
)
2701 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
2702 route
->source
, route
->sink
);
2704 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2705 if (path
->sink
== sink
) {
2712 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
2713 route
->source
, route
->sink
);
2715 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
2716 count
, route
->source
, route
->sink
);
2722 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2723 * @dapm: DAPM context
2724 * @route: audio routes
2725 * @num: number of routes
2727 * Mark existing routes matching those specified in the passed array
2728 * as being weak, meaning that they are ignored for the purpose of
2729 * power decisions. The main intended use case is for sidetone paths
2730 * which couple audio between other independent paths if they are both
2731 * active in order to make the combination work better at the user
2732 * level but which aren't intended to be "used".
2734 * Note that CODEC drivers should not use this as sidetone type paths
2735 * can frequently also be used as bypass paths.
2737 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2738 const struct snd_soc_dapm_route
*route
, int num
)
2743 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2744 for (i
= 0; i
< num
; i
++) {
2745 err
= snd_soc_dapm_weak_route(dapm
, route
);
2750 mutex_unlock(&dapm
->card
->dapm_mutex
);
2754 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2757 * snd_soc_dapm_new_widgets - add new dapm widgets
2758 * @dapm: DAPM context
2760 * Checks the codec for any new dapm widgets and creates them if found.
2762 * Returns 0 for success.
2764 int snd_soc_dapm_new_widgets(struct snd_soc_card
*card
)
2766 struct snd_soc_dapm_widget
*w
;
2769 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2771 list_for_each_entry(w
, &card
->widgets
, list
)
2776 if (w
->num_kcontrols
) {
2777 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2778 sizeof(struct snd_kcontrol
*),
2780 if (!w
->kcontrols
) {
2781 mutex_unlock(&card
->dapm_mutex
);
2787 case snd_soc_dapm_switch
:
2788 case snd_soc_dapm_mixer
:
2789 case snd_soc_dapm_mixer_named_ctl
:
2792 case snd_soc_dapm_mux
:
2793 case snd_soc_dapm_virt_mux
:
2794 case snd_soc_dapm_value_mux
:
2797 case snd_soc_dapm_pga
:
2798 case snd_soc_dapm_out_drv
:
2805 /* Read the initial power state from the device */
2807 soc_widget_read(w
, w
->reg
, &val
);
2808 val
= val
>> w
->shift
;
2810 if (val
== w
->on_val
)
2816 dapm_mark_dirty(w
, "new widget");
2817 dapm_debugfs_add_widget(w
);
2820 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2821 mutex_unlock(&card
->dapm_mutex
);
2824 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2827 * snd_soc_dapm_get_volsw - dapm mixer get callback
2828 * @kcontrol: mixer control
2829 * @ucontrol: control element information
2831 * Callback to get the value of a dapm mixer control.
2833 * Returns 0 for success.
2835 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2836 struct snd_ctl_elem_value
*ucontrol
)
2838 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2839 struct snd_soc_card
*card
= codec
->card
;
2840 struct soc_mixer_control
*mc
=
2841 (struct soc_mixer_control
*)kcontrol
->private_value
;
2843 unsigned int shift
= mc
->shift
;
2845 unsigned int mask
= (1 << fls(max
)) - 1;
2846 unsigned int invert
= mc
->invert
;
2849 if (snd_soc_volsw_is_stereo(mc
))
2850 dev_warn(codec
->dapm
.dev
,
2851 "ASoC: Control '%s' is stereo, which is not supported\n",
2854 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2855 if (dapm_kcontrol_is_powered(kcontrol
) && reg
!= SND_SOC_NOPM
)
2856 val
= (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2858 val
= dapm_kcontrol_get_value(kcontrol
);
2859 mutex_unlock(&card
->dapm_mutex
);
2862 ucontrol
->value
.integer
.value
[0] = max
- val
;
2864 ucontrol
->value
.integer
.value
[0] = val
;
2868 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2871 * snd_soc_dapm_put_volsw - dapm mixer set callback
2872 * @kcontrol: mixer control
2873 * @ucontrol: control element information
2875 * Callback to set the value of a dapm mixer control.
2877 * Returns 0 for success.
2879 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2880 struct snd_ctl_elem_value
*ucontrol
)
2882 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2883 struct snd_soc_card
*card
= codec
->card
;
2884 struct soc_mixer_control
*mc
=
2885 (struct soc_mixer_control
*)kcontrol
->private_value
;
2887 unsigned int shift
= mc
->shift
;
2889 unsigned int mask
= (1 << fls(max
)) - 1;
2890 unsigned int invert
= mc
->invert
;
2892 int connect
, change
;
2893 struct snd_soc_dapm_update update
;
2896 if (snd_soc_volsw_is_stereo(mc
))
2897 dev_warn(codec
->dapm
.dev
,
2898 "ASoC: Control '%s' is stereo, which is not supported\n",
2901 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2907 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2909 change
= dapm_kcontrol_set_value(kcontrol
, val
);
2911 if (reg
!= SND_SOC_NOPM
) {
2912 mask
= mask
<< shift
;
2915 change
= snd_soc_test_bits(codec
, reg
, mask
, val
);
2919 if (reg
!= SND_SOC_NOPM
) {
2920 update
.kcontrol
= kcontrol
;
2925 card
->update
= &update
;
2928 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
2930 card
->update
= NULL
;
2933 mutex_unlock(&card
->dapm_mutex
);
2936 soc_dpcm_runtime_update(card
);
2940 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2943 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2944 * @kcontrol: mixer control
2945 * @ucontrol: control element information
2947 * Callback to get the value of a dapm enumerated double mixer control.
2949 * Returns 0 for success.
2951 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2952 struct snd_ctl_elem_value
*ucontrol
)
2954 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2955 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2958 val
= snd_soc_read(codec
, e
->reg
);
2959 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & e
->mask
;
2960 if (e
->shift_l
!= e
->shift_r
)
2961 ucontrol
->value
.enumerated
.item
[1] =
2962 (val
>> e
->shift_r
) & e
->mask
;
2966 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2969 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2970 * @kcontrol: mixer control
2971 * @ucontrol: control element information
2973 * Callback to set the value of a dapm enumerated double mixer control.
2975 * Returns 0 for success.
2977 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2978 struct snd_ctl_elem_value
*ucontrol
)
2980 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
2981 struct snd_soc_card
*card
= codec
->card
;
2982 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2983 unsigned int val
, mux
, change
;
2985 struct snd_soc_dapm_update update
;
2988 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2990 mux
= ucontrol
->value
.enumerated
.item
[0];
2991 val
= mux
<< e
->shift_l
;
2992 mask
= e
->mask
<< e
->shift_l
;
2993 if (e
->shift_l
!= e
->shift_r
) {
2994 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2996 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2997 mask
|= e
->mask
<< e
->shift_r
;
3000 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3002 change
= snd_soc_test_bits(codec
, e
->reg
, mask
, val
);
3004 update
.kcontrol
= kcontrol
;
3005 update
.reg
= e
->reg
;
3008 card
->update
= &update
;
3010 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
3012 card
->update
= NULL
;
3015 mutex_unlock(&card
->dapm_mutex
);
3018 soc_dpcm_runtime_update(card
);
3022 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
3025 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
3026 * @kcontrol: mixer control
3027 * @ucontrol: control element information
3029 * Returns 0 for success.
3031 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
3032 struct snd_ctl_elem_value
*ucontrol
)
3034 ucontrol
->value
.enumerated
.item
[0] = dapm_kcontrol_get_value(kcontrol
);
3037 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
3040 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
3041 * @kcontrol: mixer control
3042 * @ucontrol: control element information
3044 * Returns 0 for success.
3046 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
3047 struct snd_ctl_elem_value
*ucontrol
)
3049 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
3050 struct snd_soc_card
*card
= codec
->card
;
3052 struct soc_enum
*e
=
3053 (struct soc_enum
*)kcontrol
->private_value
;
3057 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
3060 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3062 value
= ucontrol
->value
.enumerated
.item
[0];
3063 change
= dapm_kcontrol_set_value(kcontrol
, value
);
3065 ret
= soc_dapm_mux_update_power(card
, kcontrol
, value
, e
);
3067 mutex_unlock(&card
->dapm_mutex
);
3070 soc_dpcm_runtime_update(card
);
3074 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
3077 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
3079 * @kcontrol: mixer control
3080 * @ucontrol: control element information
3082 * Callback to get the value of a dapm semi enumerated double mixer control.
3084 * Semi enumerated mixer: the enumerated items are referred as values. Can be
3085 * used for handling bitfield coded enumeration for example.
3087 * Returns 0 for success.
3089 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
3090 struct snd_ctl_elem_value
*ucontrol
)
3092 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
3093 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3094 unsigned int reg_val
, val
, mux
;
3096 reg_val
= snd_soc_read(codec
, e
->reg
);
3097 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
3098 for (mux
= 0; mux
< e
->max
; mux
++) {
3099 if (val
== e
->values
[mux
])
3102 ucontrol
->value
.enumerated
.item
[0] = mux
;
3103 if (e
->shift_l
!= e
->shift_r
) {
3104 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
3105 for (mux
= 0; mux
< e
->max
; mux
++) {
3106 if (val
== e
->values
[mux
])
3109 ucontrol
->value
.enumerated
.item
[1] = mux
;
3114 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
3117 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
3119 * @kcontrol: mixer control
3120 * @ucontrol: control element information
3122 * Callback to set the value of a dapm semi enumerated double mixer control.
3124 * Semi enumerated mixer: the enumerated items are referred as values. Can be
3125 * used for handling bitfield coded enumeration for example.
3127 * Returns 0 for success.
3129 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
3130 struct snd_ctl_elem_value
*ucontrol
)
3132 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
3133 struct snd_soc_card
*card
= codec
->card
;
3134 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3135 unsigned int val
, mux
, change
;
3137 struct snd_soc_dapm_update update
;
3140 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
3142 mux
= ucontrol
->value
.enumerated
.item
[0];
3143 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
3144 mask
= e
->mask
<< e
->shift_l
;
3145 if (e
->shift_l
!= e
->shift_r
) {
3146 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
3148 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
3149 mask
|= e
->mask
<< e
->shift_r
;
3152 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3154 change
= snd_soc_test_bits(codec
, e
->reg
, mask
, val
);
3156 update
.kcontrol
= kcontrol
;
3157 update
.reg
= e
->reg
;
3160 card
->update
= &update
;
3162 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
3164 card
->update
= NULL
;
3167 mutex_unlock(&card
->dapm_mutex
);
3170 soc_dpcm_runtime_update(card
);
3174 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
3177 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3179 * @kcontrol: mixer control
3180 * @uinfo: control element information
3182 * Callback to provide information about a pin switch control.
3184 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3185 struct snd_ctl_elem_info
*uinfo
)
3187 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3189 uinfo
->value
.integer
.min
= 0;
3190 uinfo
->value
.integer
.max
= 1;
3194 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3197 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3199 * @kcontrol: mixer control
3202 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3203 struct snd_ctl_elem_value
*ucontrol
)
3205 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3206 const char *pin
= (const char *)kcontrol
->private_value
;
3208 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3210 ucontrol
->value
.integer
.value
[0] =
3211 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3213 mutex_unlock(&card
->dapm_mutex
);
3217 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3220 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3222 * @kcontrol: mixer control
3225 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3226 struct snd_ctl_elem_value
*ucontrol
)
3228 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3229 const char *pin
= (const char *)kcontrol
->private_value
;
3231 if (ucontrol
->value
.integer
.value
[0])
3232 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3234 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3236 snd_soc_dapm_sync(&card
->dapm
);
3239 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3241 static struct snd_soc_dapm_widget
*
3242 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3243 const struct snd_soc_dapm_widget
*widget
)
3245 struct snd_soc_dapm_widget
*w
;
3248 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3252 case snd_soc_dapm_regulator_supply
:
3253 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3254 if (IS_ERR(w
->regulator
)) {
3255 ret
= PTR_ERR(w
->regulator
);
3256 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3261 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3262 ret
= regulator_allow_bypass(w
->regulator
, true);
3264 dev_warn(w
->dapm
->dev
,
3265 "ASoC: Failed to bypass %s: %d\n",
3269 case snd_soc_dapm_clock_supply
:
3270 #ifdef CONFIG_CLKDEV_LOOKUP
3271 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3272 if (IS_ERR(w
->clk
)) {
3273 ret
= PTR_ERR(w
->clk
);
3274 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3286 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3287 w
->name
= kasprintf(GFP_KERNEL
, "%s %s",
3288 dapm
->codec
->name_prefix
, widget
->name
);
3290 w
->name
= kasprintf(GFP_KERNEL
, "%s", widget
->name
);
3292 if (w
->name
== NULL
) {
3298 case snd_soc_dapm_switch
:
3299 case snd_soc_dapm_mixer
:
3300 case snd_soc_dapm_mixer_named_ctl
:
3301 w
->power_check
= dapm_generic_check_power
;
3303 case snd_soc_dapm_mux
:
3304 case snd_soc_dapm_virt_mux
:
3305 case snd_soc_dapm_value_mux
:
3306 w
->power_check
= dapm_generic_check_power
;
3308 case snd_soc_dapm_dai_out
:
3309 w
->power_check
= dapm_adc_check_power
;
3311 case snd_soc_dapm_dai_in
:
3312 w
->power_check
= dapm_dac_check_power
;
3314 case snd_soc_dapm_adc
:
3315 case snd_soc_dapm_aif_out
:
3316 case snd_soc_dapm_dac
:
3317 case snd_soc_dapm_aif_in
:
3318 case snd_soc_dapm_pga
:
3319 case snd_soc_dapm_out_drv
:
3320 case snd_soc_dapm_input
:
3321 case snd_soc_dapm_output
:
3322 case snd_soc_dapm_micbias
:
3323 case snd_soc_dapm_spk
:
3324 case snd_soc_dapm_hp
:
3325 case snd_soc_dapm_mic
:
3326 case snd_soc_dapm_line
:
3327 case snd_soc_dapm_dai_link
:
3328 w
->power_check
= dapm_generic_check_power
;
3330 case snd_soc_dapm_supply
:
3331 case snd_soc_dapm_regulator_supply
:
3332 case snd_soc_dapm_clock_supply
:
3333 case snd_soc_dapm_kcontrol
:
3334 w
->power_check
= dapm_supply_check_power
;
3337 w
->power_check
= dapm_always_on_check_power
;
3342 w
->codec
= dapm
->codec
;
3343 w
->platform
= dapm
->platform
;
3344 INIT_LIST_HEAD(&w
->sources
);
3345 INIT_LIST_HEAD(&w
->sinks
);
3346 INIT_LIST_HEAD(&w
->list
);
3347 INIT_LIST_HEAD(&w
->dirty
);
3348 list_add(&w
->list
, &dapm
->card
->widgets
);
3350 /* machine layer set ups unconnected pins and insertions */
3356 * snd_soc_dapm_new_controls - create new dapm controls
3357 * @dapm: DAPM context
3358 * @widget: widget array
3359 * @num: number of widgets
3361 * Creates new DAPM controls based upon the templates.
3363 * Returns 0 for success else error.
3365 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3366 const struct snd_soc_dapm_widget
*widget
,
3369 struct snd_soc_dapm_widget
*w
;
3373 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3374 for (i
= 0; i
< num
; i
++) {
3375 w
= snd_soc_dapm_new_control(dapm
, widget
);
3378 "ASoC: Failed to create DAPM control %s\n",
3385 mutex_unlock(&dapm
->card
->dapm_mutex
);
3388 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3390 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3391 struct snd_kcontrol
*kcontrol
, int event
)
3393 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3394 struct snd_soc_dai
*source
, *sink
;
3395 const struct snd_soc_pcm_stream
*config
= w
->params
;
3396 struct snd_pcm_substream substream
;
3397 struct snd_pcm_hw_params
*params
= NULL
;
3401 if (WARN_ON(!config
) ||
3402 WARN_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
)))
3405 /* We only support a single source and sink, pick the first */
3406 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3408 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3411 if (WARN_ON(!source_p
|| !sink_p
) ||
3412 WARN_ON(!sink_p
->source
|| !source_p
->sink
) ||
3413 WARN_ON(!source_p
->source
|| !sink_p
->sink
))
3416 source
= source_p
->source
->priv
;
3417 sink
= sink_p
->sink
->priv
;
3419 /* Be a little careful as we don't want to overflow the mask array */
3420 if (config
->formats
) {
3421 fmt
= ffs(config
->formats
) - 1;
3423 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3428 /* Currently very limited parameter selection */
3429 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3434 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3436 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3438 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3441 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3442 = config
->channels_min
;
3443 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3444 = config
->channels_max
;
3446 memset(&substream
, 0, sizeof(substream
));
3449 case SND_SOC_DAPM_PRE_PMU
:
3450 if (source
->driver
->ops
&& source
->driver
->ops
->hw_params
) {
3451 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3452 ret
= source
->driver
->ops
->hw_params(&substream
,
3455 dev_err(source
->dev
,
3456 "ASoC: hw_params() failed: %d\n", ret
);
3461 if (sink
->driver
->ops
&& sink
->driver
->ops
->hw_params
) {
3462 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3463 ret
= sink
->driver
->ops
->hw_params(&substream
, params
,
3467 "ASoC: hw_params() failed: %d\n", ret
);
3473 case SND_SOC_DAPM_POST_PMU
:
3474 ret
= snd_soc_dai_digital_mute(sink
, 0,
3475 SNDRV_PCM_STREAM_PLAYBACK
);
3476 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3477 dev_warn(sink
->dev
, "ASoC: Failed to unmute: %d\n", ret
);
3481 case SND_SOC_DAPM_PRE_PMD
:
3482 ret
= snd_soc_dai_digital_mute(sink
, 1,
3483 SNDRV_PCM_STREAM_PLAYBACK
);
3484 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3485 dev_warn(sink
->dev
, "ASoC: Failed to mute: %d\n", ret
);
3490 WARN(1, "Unknown event %d\n", event
);
3499 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3500 const struct snd_soc_pcm_stream
*params
,
3501 struct snd_soc_dapm_widget
*source
,
3502 struct snd_soc_dapm_widget
*sink
)
3504 struct snd_soc_dapm_route routes
[2];
3505 struct snd_soc_dapm_widget
template;
3506 struct snd_soc_dapm_widget
*w
;
3510 len
= strlen(source
->name
) + strlen(sink
->name
) + 2;
3511 link_name
= devm_kzalloc(card
->dev
, len
, GFP_KERNEL
);
3514 snprintf(link_name
, len
, "%s-%s", source
->name
, sink
->name
);
3516 memset(&template, 0, sizeof(template));
3517 template.reg
= SND_SOC_NOPM
;
3518 template.id
= snd_soc_dapm_dai_link
;
3519 template.name
= link_name
;
3520 template.event
= snd_soc_dai_link_event
;
3521 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3522 SND_SOC_DAPM_PRE_PMD
;
3524 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
3526 w
= snd_soc_dapm_new_control(&card
->dapm
, &template);
3528 dev_err(card
->dev
, "ASoC: Failed to create %s widget\n",
3535 memset(&routes
, 0, sizeof(routes
));
3537 routes
[0].source
= source
->name
;
3538 routes
[0].sink
= link_name
;
3539 routes
[1].source
= link_name
;
3540 routes
[1].sink
= sink
->name
;
3542 return snd_soc_dapm_add_routes(&card
->dapm
, routes
,
3543 ARRAY_SIZE(routes
));
3546 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3547 struct snd_soc_dai
*dai
)
3549 struct snd_soc_dapm_widget
template;
3550 struct snd_soc_dapm_widget
*w
;
3552 WARN_ON(dapm
->dev
!= dai
->dev
);
3554 memset(&template, 0, sizeof(template));
3555 template.reg
= SND_SOC_NOPM
;
3557 if (dai
->driver
->playback
.stream_name
) {
3558 template.id
= snd_soc_dapm_dai_in
;
3559 template.name
= dai
->driver
->playback
.stream_name
;
3560 template.sname
= dai
->driver
->playback
.stream_name
;
3562 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3565 w
= snd_soc_dapm_new_control(dapm
, &template);
3567 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3568 dai
->driver
->playback
.stream_name
);
3573 dai
->playback_widget
= w
;
3576 if (dai
->driver
->capture
.stream_name
) {
3577 template.id
= snd_soc_dapm_dai_out
;
3578 template.name
= dai
->driver
->capture
.stream_name
;
3579 template.sname
= dai
->driver
->capture
.stream_name
;
3581 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3584 w
= snd_soc_dapm_new_control(dapm
, &template);
3586 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3587 dai
->driver
->capture
.stream_name
);
3592 dai
->capture_widget
= w
;
3598 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3600 struct snd_soc_dapm_widget
*dai_w
, *w
;
3601 struct snd_soc_dai
*dai
;
3603 /* For each DAI widget... */
3604 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3605 switch (dai_w
->id
) {
3606 case snd_soc_dapm_dai_in
:
3607 case snd_soc_dapm_dai_out
:
3615 /* ...find all widgets with the same stream and link them */
3616 list_for_each_entry(w
, &card
->widgets
, list
) {
3617 if (w
->dapm
!= dai_w
->dapm
)
3621 case snd_soc_dapm_dai_in
:
3622 case snd_soc_dapm_dai_out
:
3628 if (!w
->sname
|| !strstr(w
->sname
, dai_w
->name
))
3631 if (dai
->driver
->playback
.stream_name
&&
3633 dai
->driver
->playback
.stream_name
)) {
3634 dev_dbg(dai
->dev
, "%s -> %s\n",
3635 dai
->playback_widget
->name
, w
->name
);
3637 snd_soc_dapm_add_path(w
->dapm
,
3638 dai
->playback_widget
, w
, NULL
, NULL
);
3641 if (dai
->driver
->capture
.stream_name
&&
3643 dai
->driver
->capture
.stream_name
)) {
3644 dev_dbg(dai
->dev
, "%s -> %s\n",
3645 w
->name
, dai
->capture_widget
->name
);
3647 snd_soc_dapm_add_path(w
->dapm
, w
,
3648 dai
->capture_widget
, NULL
, NULL
);
3656 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card
*card
)
3658 struct snd_soc_pcm_runtime
*rtd
= card
->rtd
;
3659 struct snd_soc_dai
*cpu_dai
, *codec_dai
;
3660 struct snd_soc_dapm_route r
;
3663 memset(&r
, 0, sizeof(r
));
3665 /* for each BE DAI link... */
3666 for (i
= 0; i
< card
->num_rtd
; i
++) {
3667 rtd
= &card
->rtd
[i
];
3668 cpu_dai
= rtd
->cpu_dai
;
3669 codec_dai
= rtd
->codec_dai
;
3671 /* dynamic FE links have no fixed DAI mapping */
3672 if (rtd
->dai_link
->dynamic
)
3675 /* there is no point in connecting BE DAI links with dummies */
3676 if (snd_soc_dai_is_dummy(codec_dai
) ||
3677 snd_soc_dai_is_dummy(cpu_dai
))
3680 /* connect BE DAI playback if widgets are valid */
3681 if (codec_dai
->playback_widget
&& cpu_dai
->playback_widget
) {
3682 r
.source
= cpu_dai
->playback_widget
->name
;
3683 r
.sink
= codec_dai
->playback_widget
->name
;
3684 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3685 cpu_dai
->codec
->name
, r
.source
,
3686 codec_dai
->platform
->name
, r
.sink
);
3688 snd_soc_dapm_add_route(&card
->dapm
, &r
, true);
3691 /* connect BE DAI capture if widgets are valid */
3692 if (codec_dai
->capture_widget
&& cpu_dai
->capture_widget
) {
3693 r
.source
= codec_dai
->capture_widget
->name
;
3694 r
.sink
= cpu_dai
->capture_widget
->name
;
3695 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3696 codec_dai
->codec
->name
, r
.source
,
3697 cpu_dai
->platform
->name
, r
.sink
);
3699 snd_soc_dapm_add_route(&card
->dapm
, &r
, true);
3705 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3709 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
3710 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3711 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
3713 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3714 w_cpu
= cpu_dai
->playback_widget
;
3715 w_codec
= codec_dai
->playback_widget
;
3717 w_cpu
= cpu_dai
->capture_widget
;
3718 w_codec
= codec_dai
->capture_widget
;
3723 dapm_mark_dirty(w_cpu
, "stream event");
3726 case SND_SOC_DAPM_STREAM_START
:
3729 case SND_SOC_DAPM_STREAM_STOP
:
3732 case SND_SOC_DAPM_STREAM_SUSPEND
:
3733 case SND_SOC_DAPM_STREAM_RESUME
:
3734 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3735 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3742 dapm_mark_dirty(w_codec
, "stream event");
3745 case SND_SOC_DAPM_STREAM_START
:
3746 w_codec
->active
= 1;
3748 case SND_SOC_DAPM_STREAM_STOP
:
3749 w_codec
->active
= 0;
3751 case SND_SOC_DAPM_STREAM_SUSPEND
:
3752 case SND_SOC_DAPM_STREAM_RESUME
:
3753 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3754 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3759 dapm_power_widgets(rtd
->card
, event
);
3763 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3764 * @rtd: PCM runtime data
3765 * @stream: stream name
3766 * @event: stream event
3768 * Sends a stream event to the dapm core. The core then makes any
3769 * necessary widget power changes.
3771 * Returns 0 for success else error.
3773 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3776 struct snd_soc_card
*card
= rtd
->card
;
3778 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3779 soc_dapm_stream_event(rtd
, stream
, event
);
3780 mutex_unlock(&card
->dapm_mutex
);
3784 * snd_soc_dapm_enable_pin_unlocked - enable pin.
3785 * @dapm: DAPM context
3788 * Enables input/output pin and its parents or children widgets iff there is
3789 * a valid audio route and active audio stream.
3791 * Requires external locking.
3793 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3794 * do any widget power switching.
3796 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3799 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3801 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked
);
3804 * snd_soc_dapm_enable_pin - enable pin.
3805 * @dapm: DAPM context
3808 * Enables input/output pin and its parents or children widgets iff there is
3809 * a valid audio route and active audio stream.
3811 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3812 * do any widget power switching.
3814 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3818 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3820 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 1);
3822 mutex_unlock(&dapm
->card
->dapm_mutex
);
3826 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3829 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
3830 * @dapm: DAPM context
3833 * Enables input/output pin regardless of any other state. This is
3834 * intended for use with microphone bias supplies used in microphone
3837 * Requires external locking.
3839 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3840 * do any widget power switching.
3842 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3845 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3848 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
3852 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
3855 dapm_mark_dirty(w
, "force enable");
3859 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked
);
3862 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3863 * @dapm: DAPM context
3866 * Enables input/output pin regardless of any other state. This is
3867 * intended for use with microphone bias supplies used in microphone
3870 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3871 * do any widget power switching.
3873 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3878 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3880 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
3882 mutex_unlock(&dapm
->card
->dapm_mutex
);
3886 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3889 * snd_soc_dapm_disable_pin_unlocked - disable pin.
3890 * @dapm: DAPM context
3893 * Disables input/output pin and its parents or children widgets.
3895 * Requires external locking.
3897 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3898 * do any widget power switching.
3900 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3903 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3905 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked
);
3908 * snd_soc_dapm_disable_pin - disable pin.
3909 * @dapm: DAPM context
3912 * Disables input/output pin and its parents or children widgets.
3914 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3915 * do any widget power switching.
3917 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3922 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3924 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
3926 mutex_unlock(&dapm
->card
->dapm_mutex
);
3930 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3933 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
3934 * @dapm: DAPM context
3937 * Marks the specified pin as being not connected, disabling it along
3938 * any parent or child widgets. At present this is identical to
3939 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3940 * additional things such as disabling controls which only affect
3941 * paths through the pin.
3943 * Requires external locking.
3945 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3946 * do any widget power switching.
3948 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3951 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3953 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked
);
3956 * snd_soc_dapm_nc_pin - permanently disable pin.
3957 * @dapm: DAPM context
3960 * Marks the specified pin as being not connected, disabling it along
3961 * any parent or child widgets. At present this is identical to
3962 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3963 * additional things such as disabling controls which only affect
3964 * paths through the pin.
3966 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3967 * do any widget power switching.
3969 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3973 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3975 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
3977 mutex_unlock(&dapm
->card
->dapm_mutex
);
3981 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3984 * snd_soc_dapm_get_pin_status - get audio pin status
3985 * @dapm: DAPM context
3986 * @pin: audio signal pin endpoint (or start point)
3988 * Get audio pin status - connected or disconnected.
3990 * Returns 1 for connected otherwise 0.
3992 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3995 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3998 return w
->connected
;
4002 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
4005 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4006 * @dapm: DAPM context
4007 * @pin: audio signal pin endpoint (or start point)
4009 * Mark the given endpoint or pin as ignoring suspend. When the
4010 * system is disabled a path between two endpoints flagged as ignoring
4011 * suspend will not be disabled. The path must already be enabled via
4012 * normal means at suspend time, it will not be turned on if it was not
4015 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
4018 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
4021 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4025 w
->ignore_suspend
= 1;
4029 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
4031 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
4032 struct snd_soc_dapm_widget
*w
)
4034 struct snd_soc_dapm_path
*p
;
4036 list_for_each_entry(p
, &card
->paths
, list
) {
4037 if ((p
->source
== w
) || (p
->sink
== w
)) {
4039 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
4040 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
4041 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
4043 /* Connected to something other than the codec */
4044 if (p
->source
->dapm
!= p
->sink
->dapm
)
4047 * Loopback connection from codec external pin to
4048 * codec external pin
4050 if (p
->sink
->id
== snd_soc_dapm_input
) {
4051 switch (p
->source
->id
) {
4052 case snd_soc_dapm_output
:
4053 case snd_soc_dapm_micbias
:
4066 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
4067 * @codec: The codec whose pins should be processed
4069 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
4070 * which are unused. Pins are used if they are connected externally to the
4071 * codec, whether that be to some other device, or a loop-back connection to
4074 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
4076 struct snd_soc_card
*card
= codec
->card
;
4077 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
4078 struct snd_soc_dapm_widget
*w
;
4080 dev_dbg(codec
->dev
, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n",
4081 &card
->dapm
, &codec
->dapm
);
4083 list_for_each_entry(w
, &card
->widgets
, list
) {
4084 if (w
->dapm
!= dapm
)
4087 case snd_soc_dapm_input
:
4088 case snd_soc_dapm_output
:
4089 case snd_soc_dapm_micbias
:
4090 dev_dbg(codec
->dev
, "ASoC: Auto NC: Checking widget %s\n",
4092 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
4094 "... Not in map; disabling\n");
4095 snd_soc_dapm_nc_pin(dapm
, w
->name
);
4105 * snd_soc_dapm_free - free dapm resources
4106 * @dapm: DAPM context
4108 * Free all dapm widgets and resources.
4110 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
4112 snd_soc_dapm_sys_remove(dapm
->dev
);
4113 dapm_debugfs_cleanup(dapm
);
4114 dapm_free_widgets(dapm
);
4115 list_del(&dapm
->list
);
4117 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
4119 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
4121 struct snd_soc_card
*card
= dapm
->card
;
4122 struct snd_soc_dapm_widget
*w
;
4123 LIST_HEAD(down_list
);
4126 mutex_lock(&card
->dapm_mutex
);
4128 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
4129 if (w
->dapm
!= dapm
)
4132 dapm_seq_insert(w
, &down_list
, false);
4138 /* If there were no widgets to power down we're already in
4142 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
4143 snd_soc_dapm_set_bias_level(dapm
,
4144 SND_SOC_BIAS_PREPARE
);
4145 dapm_seq_run(card
, &down_list
, 0, false);
4146 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
4147 snd_soc_dapm_set_bias_level(dapm
,
4148 SND_SOC_BIAS_STANDBY
);
4151 mutex_unlock(&card
->dapm_mutex
);
4155 * snd_soc_dapm_shutdown - callback for system shutdown
4157 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
4159 struct snd_soc_codec
*codec
;
4161 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
4162 soc_dapm_shutdown_codec(&codec
->dapm
);
4163 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
4164 snd_soc_dapm_set_bias_level(&codec
->dapm
,
4169 /* Module information */
4170 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4171 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4172 MODULE_LICENSE("GPL");