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 /* dapm power sequences - make this per codec in the future */
51 static int dapm_up_seq
[] = {
52 [snd_soc_dapm_pre
] = 0,
53 [snd_soc_dapm_supply
] = 1,
54 [snd_soc_dapm_regulator_supply
] = 1,
55 [snd_soc_dapm_clock_supply
] = 1,
56 [snd_soc_dapm_micbias
] = 2,
57 [snd_soc_dapm_dai_link
] = 2,
58 [snd_soc_dapm_dai
] = 3,
59 [snd_soc_dapm_aif_in
] = 3,
60 [snd_soc_dapm_aif_out
] = 3,
61 [snd_soc_dapm_mic
] = 4,
62 [snd_soc_dapm_mux
] = 5,
63 [snd_soc_dapm_virt_mux
] = 5,
64 [snd_soc_dapm_value_mux
] = 5,
65 [snd_soc_dapm_dac
] = 6,
66 [snd_soc_dapm_mixer
] = 7,
67 [snd_soc_dapm_mixer_named_ctl
] = 7,
68 [snd_soc_dapm_pga
] = 8,
69 [snd_soc_dapm_adc
] = 9,
70 [snd_soc_dapm_out_drv
] = 10,
71 [snd_soc_dapm_hp
] = 10,
72 [snd_soc_dapm_spk
] = 10,
73 [snd_soc_dapm_line
] = 10,
74 [snd_soc_dapm_post
] = 11,
77 static int dapm_down_seq
[] = {
78 [snd_soc_dapm_pre
] = 0,
79 [snd_soc_dapm_adc
] = 1,
80 [snd_soc_dapm_hp
] = 2,
81 [snd_soc_dapm_spk
] = 2,
82 [snd_soc_dapm_line
] = 2,
83 [snd_soc_dapm_out_drv
] = 2,
84 [snd_soc_dapm_pga
] = 4,
85 [snd_soc_dapm_mixer_named_ctl
] = 5,
86 [snd_soc_dapm_mixer
] = 5,
87 [snd_soc_dapm_dac
] = 6,
88 [snd_soc_dapm_mic
] = 7,
89 [snd_soc_dapm_micbias
] = 8,
90 [snd_soc_dapm_mux
] = 9,
91 [snd_soc_dapm_virt_mux
] = 9,
92 [snd_soc_dapm_value_mux
] = 9,
93 [snd_soc_dapm_aif_in
] = 10,
94 [snd_soc_dapm_aif_out
] = 10,
95 [snd_soc_dapm_dai
] = 10,
96 [snd_soc_dapm_dai_link
] = 11,
97 [snd_soc_dapm_clock_supply
] = 12,
98 [snd_soc_dapm_regulator_supply
] = 12,
99 [snd_soc_dapm_supply
] = 12,
100 [snd_soc_dapm_post
] = 13,
103 static void pop_wait(u32 pop_time
)
106 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
109 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
117 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
122 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
123 dev_info(dev
, "%s", buf
);
129 static bool dapm_dirty_widget(struct snd_soc_dapm_widget
*w
)
131 return !list_empty(&w
->dirty
);
134 void dapm_mark_dirty(struct snd_soc_dapm_widget
*w
, const char *reason
)
136 if (!dapm_dirty_widget(w
)) {
137 dev_vdbg(w
->dapm
->dev
, "Marking %s dirty due to %s\n",
139 list_add_tail(&w
->dirty
, &w
->dapm
->card
->dapm_dirty
);
142 EXPORT_SYMBOL_GPL(dapm_mark_dirty
);
144 void dapm_mark_io_dirty(struct snd_soc_dapm_context
*dapm
)
146 struct snd_soc_card
*card
= dapm
->card
;
147 struct snd_soc_dapm_widget
*w
;
149 mutex_lock(&card
->dapm_mutex
);
151 list_for_each_entry(w
, &card
->widgets
, list
) {
153 case snd_soc_dapm_input
:
154 case snd_soc_dapm_output
:
155 dapm_mark_dirty(w
, "Rechecking inputs and outputs");
162 mutex_unlock(&card
->dapm_mutex
);
164 EXPORT_SYMBOL_GPL(dapm_mark_io_dirty
);
166 /* create a new dapm widget */
167 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
168 const struct snd_soc_dapm_widget
*_widget
)
170 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
173 /* get snd_card from DAPM context */
174 static inline struct snd_card
*dapm_get_snd_card(
175 struct snd_soc_dapm_context
*dapm
)
178 return dapm
->codec
->card
->snd_card
;
179 else if (dapm
->platform
)
180 return dapm
->platform
->card
->snd_card
;
188 /* get soc_card from DAPM context */
189 static inline struct snd_soc_card
*dapm_get_soc_card(
190 struct snd_soc_dapm_context
*dapm
)
193 return dapm
->codec
->card
;
194 else if (dapm
->platform
)
195 return dapm
->platform
->card
;
203 static void dapm_reset(struct snd_soc_card
*card
)
205 struct snd_soc_dapm_widget
*w
;
207 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
209 list_for_each_entry(w
, &card
->widgets
, list
) {
210 w
->power_checked
= false;
216 static int soc_widget_read(struct snd_soc_dapm_widget
*w
, int reg
)
219 return snd_soc_read(w
->codec
, reg
);
220 else if (w
->platform
)
221 return snd_soc_platform_read(w
->platform
, reg
);
223 dev_err(w
->dapm
->dev
, "ASoC: no valid widget read method\n");
227 static int soc_widget_write(struct snd_soc_dapm_widget
*w
, int reg
, int val
)
230 return snd_soc_write(w
->codec
, reg
, val
);
231 else if (w
->platform
)
232 return snd_soc_platform_write(w
->platform
, reg
, val
);
234 dev_err(w
->dapm
->dev
, "ASoC: no valid widget write method\n");
238 static inline void soc_widget_lock(struct snd_soc_dapm_widget
*w
)
240 if (w
->codec
&& !w
->codec
->using_regmap
)
241 mutex_lock(&w
->codec
->mutex
);
242 else if (w
->platform
)
243 mutex_lock(&w
->platform
->mutex
);
246 static inline void soc_widget_unlock(struct snd_soc_dapm_widget
*w
)
248 if (w
->codec
&& !w
->codec
->using_regmap
)
249 mutex_unlock(&w
->codec
->mutex
);
250 else if (w
->platform
)
251 mutex_unlock(&w
->platform
->mutex
);
254 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget
*w
,
255 unsigned short reg
, unsigned int mask
, unsigned int value
)
258 unsigned int old
, new;
261 if (w
->codec
&& w
->codec
->using_regmap
) {
262 ret
= regmap_update_bits_check(w
->codec
->control_data
,
263 reg
, mask
, value
, &change
);
268 ret
= soc_widget_read(w
, reg
);
270 soc_widget_unlock(w
);
275 new = (old
& ~mask
) | (value
& mask
);
278 ret
= soc_widget_write(w
, reg
, new);
280 soc_widget_unlock(w
);
284 soc_widget_unlock(w
);
291 * snd_soc_dapm_set_bias_level - set the bias level for the system
292 * @dapm: DAPM context
293 * @level: level to configure
295 * Configure the bias (power) levels for the SoC audio device.
297 * Returns 0 for success else error.
299 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
300 enum snd_soc_bias_level level
)
302 struct snd_soc_card
*card
= dapm
->card
;
305 trace_snd_soc_bias_level_start(card
, level
);
307 if (card
&& card
->set_bias_level
)
308 ret
= card
->set_bias_level(card
, dapm
, level
);
313 if (dapm
->codec
->driver
->set_bias_level
)
314 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
317 dapm
->bias_level
= level
;
318 } else if (!card
|| dapm
!= &card
->dapm
) {
319 dapm
->bias_level
= level
;
325 if (card
&& card
->set_bias_level_post
)
326 ret
= card
->set_bias_level_post(card
, dapm
, level
);
328 trace_snd_soc_bias_level_done(card
, level
);
333 /* set up initial codec paths */
334 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
335 struct snd_soc_dapm_path
*p
, int i
)
338 case snd_soc_dapm_switch
:
339 case snd_soc_dapm_mixer
:
340 case snd_soc_dapm_mixer_named_ctl
: {
342 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
343 w
->kcontrol_news
[i
].private_value
;
344 unsigned int reg
= mc
->reg
;
345 unsigned int shift
= mc
->shift
;
347 unsigned int mask
= (1 << fls(max
)) - 1;
348 unsigned int invert
= mc
->invert
;
350 val
= soc_widget_read(w
, reg
);
351 val
= (val
>> shift
) & mask
;
358 case snd_soc_dapm_mux
: {
359 struct soc_enum
*e
= (struct soc_enum
*)
360 w
->kcontrol_news
[i
].private_value
;
363 val
= soc_widget_read(w
, e
->reg
);
364 item
= (val
>> e
->shift_l
) & e
->mask
;
367 for (i
= 0; i
< e
->max
; i
++) {
368 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
373 case snd_soc_dapm_virt_mux
: {
374 struct soc_enum
*e
= (struct soc_enum
*)
375 w
->kcontrol_news
[i
].private_value
;
378 /* since a virtual mux has no backing registers to
379 * decide which path to connect, it will try to match
380 * with the first enumeration. This is to ensure
381 * that the default mux choice (the first) will be
382 * correctly powered up during initialization.
384 if (!strcmp(p
->name
, e
->texts
[0]))
388 case snd_soc_dapm_value_mux
: {
389 struct soc_enum
*e
= (struct soc_enum
*)
390 w
->kcontrol_news
[i
].private_value
;
393 val
= soc_widget_read(w
, e
->reg
);
394 val
= (val
>> e
->shift_l
) & e
->mask
;
395 for (item
= 0; item
< e
->max
; item
++) {
396 if (val
== e
->values
[item
])
401 for (i
= 0; i
< e
->max
; i
++) {
402 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
407 /* does not affect routing - always connected */
408 case snd_soc_dapm_pga
:
409 case snd_soc_dapm_out_drv
:
410 case snd_soc_dapm_output
:
411 case snd_soc_dapm_adc
:
412 case snd_soc_dapm_input
:
413 case snd_soc_dapm_siggen
:
414 case snd_soc_dapm_dac
:
415 case snd_soc_dapm_micbias
:
416 case snd_soc_dapm_vmid
:
417 case snd_soc_dapm_supply
:
418 case snd_soc_dapm_regulator_supply
:
419 case snd_soc_dapm_clock_supply
:
420 case snd_soc_dapm_aif_in
:
421 case snd_soc_dapm_aif_out
:
422 case snd_soc_dapm_dai
:
423 case snd_soc_dapm_hp
:
424 case snd_soc_dapm_mic
:
425 case snd_soc_dapm_spk
:
426 case snd_soc_dapm_line
:
427 case snd_soc_dapm_dai_link
:
430 /* does affect routing - dynamically connected */
431 case snd_soc_dapm_pre
:
432 case snd_soc_dapm_post
:
438 /* connect mux widget to its interconnecting audio paths */
439 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
440 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
441 struct snd_soc_dapm_path
*path
, const char *control_name
,
442 const struct snd_kcontrol_new
*kcontrol
)
444 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
447 for (i
= 0; i
< e
->max
; i
++) {
448 if (!(strcmp(control_name
, e
->texts
[i
]))) {
449 list_add(&path
->list
, &dapm
->card
->paths
);
450 list_add(&path
->list_sink
, &dest
->sources
);
451 list_add(&path
->list_source
, &src
->sinks
);
452 path
->name
= (char*)e
->texts
[i
];
453 dapm_set_path_status(dest
, path
, 0);
461 /* connect mixer widget to its interconnecting audio paths */
462 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
463 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
464 struct snd_soc_dapm_path
*path
, const char *control_name
)
468 /* search for mixer kcontrol */
469 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
470 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
471 list_add(&path
->list
, &dapm
->card
->paths
);
472 list_add(&path
->list_sink
, &dest
->sources
);
473 list_add(&path
->list_source
, &src
->sinks
);
474 path
->name
= dest
->kcontrol_news
[i
].name
;
475 dapm_set_path_status(dest
, path
, i
);
482 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
483 struct snd_soc_dapm_widget
*kcontrolw
,
484 const struct snd_kcontrol_new
*kcontrol_new
,
485 struct snd_kcontrol
**kcontrol
)
487 struct snd_soc_dapm_widget
*w
;
492 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
493 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
495 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
496 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
498 *kcontrol
= w
->kcontrols
[i
];
508 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
509 * create it. Either way, add the widget into the control's widget list
511 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget
*w
,
512 int kci
, struct snd_soc_dapm_path
*path
)
514 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
515 struct snd_card
*card
= dapm
->card
->snd_card
;
519 struct snd_kcontrol
*kcontrol
;
520 struct snd_soc_dapm_widget_list
*wlist
;
523 bool wname_in_long_name
, kcname_in_long_name
;
530 prefix
= dapm
->codec
->name_prefix
;
535 prefix_len
= strlen(prefix
) + 1;
539 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
543 wlist
= kcontrol
->private_data
;
544 wlistentries
= wlist
->num_widgets
+ 1;
550 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
551 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
552 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
554 dev_err(dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
558 wlist
->num_widgets
= wlistentries
;
559 wlist
->widgets
[wlistentries
- 1] = w
;
563 wname_in_long_name
= false;
564 kcname_in_long_name
= true;
567 case snd_soc_dapm_switch
:
568 case snd_soc_dapm_mixer
:
569 wname_in_long_name
= true;
570 kcname_in_long_name
= true;
572 case snd_soc_dapm_mixer_named_ctl
:
573 wname_in_long_name
= false;
574 kcname_in_long_name
= true;
576 case snd_soc_dapm_mux
:
577 case snd_soc_dapm_virt_mux
:
578 case snd_soc_dapm_value_mux
:
579 wname_in_long_name
= true;
580 kcname_in_long_name
= false;
588 if (wname_in_long_name
&& kcname_in_long_name
) {
589 name_len
= strlen(w
->name
) - prefix_len
+ 1 +
590 strlen(w
->kcontrol_news
[kci
].name
) + 1;
592 long_name
= kmalloc(name_len
, GFP_KERNEL
);
593 if (long_name
== NULL
) {
599 * The control will get a prefix from the control
600 * creation process but we're also using the same
601 * prefix for widgets so cut the prefix off the
602 * front of the widget name.
604 snprintf(long_name
, name_len
, "%s %s",
605 w
->name
+ prefix_len
,
606 w
->kcontrol_news
[kci
].name
);
607 long_name
[name_len
- 1] = '\0';
610 } else if (wname_in_long_name
) {
612 name
= w
->name
+ prefix_len
;
615 name
= w
->kcontrol_news
[kci
].name
;
618 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], wlist
, name
,
620 ret
= snd_ctl_add(card
, kcontrol
);
623 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
630 path
->long_name
= long_name
;
633 kcontrol
->private_data
= wlist
;
634 w
->kcontrols
[kci
] = kcontrol
;
635 path
->kcontrol
= kcontrol
;
640 /* create new dapm mixer control */
641 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
644 struct snd_soc_dapm_path
*path
;
647 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
649 list_for_each_entry(path
, &w
->sources
, list_sink
) {
650 /* mixer/mux paths name must match control name */
651 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
654 if (w
->kcontrols
[i
]) {
655 path
->kcontrol
= w
->kcontrols
[i
];
659 ret
= dapm_create_or_share_mixmux_kcontrol(w
, i
, path
);
668 /* create new dapm mux control */
669 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
671 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
672 struct snd_soc_dapm_path
*path
;
675 if (w
->num_kcontrols
!= 1) {
677 "ASoC: mux %s has incorrect number of controls\n",
682 path
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
685 dev_err(dapm
->dev
, "ASoC: mux %s has no paths\n", w
->name
);
689 ret
= dapm_create_or_share_mixmux_kcontrol(w
, 0, path
);
693 list_for_each_entry(path
, &w
->sources
, list_sink
)
694 path
->kcontrol
= w
->kcontrols
[0];
699 /* create new dapm volume control */
700 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
702 if (w
->num_kcontrols
)
703 dev_err(w
->dapm
->dev
,
704 "ASoC: PGA controls not supported: '%s'\n", w
->name
);
709 /* reset 'walked' bit for each dapm path */
710 static void dapm_clear_walk_output(struct snd_soc_dapm_context
*dapm
,
711 struct list_head
*sink
)
713 struct snd_soc_dapm_path
*p
;
715 list_for_each_entry(p
, sink
, list_source
) {
718 dapm_clear_walk_output(dapm
, &p
->sink
->sinks
);
723 static void dapm_clear_walk_input(struct snd_soc_dapm_context
*dapm
,
724 struct list_head
*source
)
726 struct snd_soc_dapm_path
*p
;
728 list_for_each_entry(p
, source
, list_sink
) {
731 dapm_clear_walk_input(dapm
, &p
->source
->sources
);
737 /* We implement power down on suspend by checking the power state of
738 * the ALSA card - when we are suspending the ALSA state for the card
741 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
743 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
746 case SNDRV_CTL_POWER_D3hot
:
747 case SNDRV_CTL_POWER_D3cold
:
748 if (widget
->ignore_suspend
)
749 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
751 return widget
->ignore_suspend
;
757 /* add widget to list if it's not already in the list */
758 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
759 struct snd_soc_dapm_widget
*w
)
761 struct snd_soc_dapm_widget_list
*wlist
;
762 int wlistsize
, wlistentries
, i
;
769 /* is this widget already in the list */
770 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
771 if (wlist
->widgets
[i
] == w
)
775 /* allocate some new space */
776 wlistentries
= wlist
->num_widgets
+ 1;
777 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
778 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
779 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
781 dev_err(w
->dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
787 /* insert the widget */
788 dev_dbg(w
->dapm
->dev
, "ASoC: added %s in widget list pos %d\n",
789 w
->name
, wlist
->num_widgets
);
791 wlist
->widgets
[wlist
->num_widgets
] = w
;
792 wlist
->num_widgets
++;
797 * Recursively check for a completed path to an active or physically connected
798 * output widget. Returns number of complete paths.
800 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
801 struct snd_soc_dapm_widget_list
**list
)
803 struct snd_soc_dapm_path
*path
;
806 if (widget
->outputs
>= 0)
807 return widget
->outputs
;
809 DAPM_UPDATE_STAT(widget
, path_checks
);
811 switch (widget
->id
) {
812 case snd_soc_dapm_supply
:
813 case snd_soc_dapm_regulator_supply
:
814 case snd_soc_dapm_clock_supply
:
820 switch (widget
->id
) {
821 case snd_soc_dapm_adc
:
822 case snd_soc_dapm_aif_out
:
823 case snd_soc_dapm_dai
:
824 if (widget
->active
) {
825 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
826 return widget
->outputs
;
832 if (widget
->connected
) {
833 /* connected pin ? */
834 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
835 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
836 return widget
->outputs
;
839 /* connected jack or spk ? */
840 if (widget
->id
== snd_soc_dapm_hp
||
841 widget
->id
== snd_soc_dapm_spk
||
842 (widget
->id
== snd_soc_dapm_line
&&
843 !list_empty(&widget
->sources
))) {
844 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
845 return widget
->outputs
;
849 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
850 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
861 trace_snd_soc_dapm_output_path(widget
, path
);
863 if (path
->sink
&& path
->connect
) {
867 /* do we need to add this widget to the list ? */
870 err
= dapm_list_add_widget(list
, path
->sink
);
872 dev_err(widget
->dapm
->dev
,
873 "ASoC: could not add widget %s\n",
880 con
+= is_connected_output_ep(path
->sink
, list
);
886 widget
->outputs
= con
;
892 * Recursively check for a completed path to an active or physically connected
893 * input widget. Returns number of complete paths.
895 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
896 struct snd_soc_dapm_widget_list
**list
)
898 struct snd_soc_dapm_path
*path
;
901 if (widget
->inputs
>= 0)
902 return widget
->inputs
;
904 DAPM_UPDATE_STAT(widget
, path_checks
);
906 switch (widget
->id
) {
907 case snd_soc_dapm_supply
:
908 case snd_soc_dapm_regulator_supply
:
909 case snd_soc_dapm_clock_supply
:
915 /* active stream ? */
916 switch (widget
->id
) {
917 case snd_soc_dapm_dac
:
918 case snd_soc_dapm_aif_in
:
919 case snd_soc_dapm_dai
:
920 if (widget
->active
) {
921 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
922 return widget
->inputs
;
928 if (widget
->connected
) {
929 /* connected pin ? */
930 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
931 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
932 return widget
->inputs
;
935 /* connected VMID/Bias for lower pops */
936 if (widget
->id
== snd_soc_dapm_vmid
) {
937 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
938 return widget
->inputs
;
941 /* connected jack ? */
942 if (widget
->id
== snd_soc_dapm_mic
||
943 (widget
->id
== snd_soc_dapm_line
&&
944 !list_empty(&widget
->sinks
))) {
945 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
946 return widget
->inputs
;
949 /* signal generator */
950 if (widget
->id
== snd_soc_dapm_siggen
) {
951 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
952 return widget
->inputs
;
956 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
957 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
968 trace_snd_soc_dapm_input_path(widget
, path
);
970 if (path
->source
&& path
->connect
) {
974 /* do we need to add this widget to the list ? */
977 err
= dapm_list_add_widget(list
, path
->source
);
979 dev_err(widget
->dapm
->dev
,
980 "ASoC: could not add widget %s\n",
987 con
+= is_connected_input_ep(path
->source
, list
);
993 widget
->inputs
= con
;
999 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1000 * @dai: the soc DAI.
1001 * @stream: stream direction.
1002 * @list: list of active widgets for this stream.
1004 * Queries DAPM graph as to whether an valid audio stream path exists for
1005 * the initial stream specified by name. This takes into account
1006 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1008 * Returns the number of valid paths or negative error.
1010 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1011 struct snd_soc_dapm_widget_list
**list
)
1013 struct snd_soc_card
*card
= dai
->card
;
1016 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1019 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1020 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
1021 dapm_clear_walk_output(&card
->dapm
,
1022 &dai
->playback_widget
->sinks
);
1024 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
1025 dapm_clear_walk_input(&card
->dapm
,
1026 &dai
->capture_widget
->sources
);
1029 trace_snd_soc_dapm_connected(paths
, stream
);
1030 mutex_unlock(&card
->dapm_mutex
);
1036 * Handler for generic register modifier widget.
1038 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
1039 struct snd_kcontrol
*kcontrol
, int event
)
1043 if (SND_SOC_DAPM_EVENT_ON(event
))
1048 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
1049 w
->mask
<< w
->shift
, val
<< w
->shift
);
1053 EXPORT_SYMBOL_GPL(dapm_reg_event
);
1056 * Handler for regulator supply widget.
1058 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1059 struct snd_kcontrol
*kcontrol
, int event
)
1063 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1064 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1065 ret
= regulator_allow_bypass(w
->regulator
, false);
1067 dev_warn(w
->dapm
->dev
,
1068 "ASoC: Failed to bypass %s: %d\n",
1072 return regulator_enable(w
->regulator
);
1074 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1075 ret
= regulator_allow_bypass(w
->regulator
, true);
1077 dev_warn(w
->dapm
->dev
,
1078 "ASoC: Failed to unbypass %s: %d\n",
1082 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1085 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1088 * Handler for clock supply widget.
1090 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1091 struct snd_kcontrol
*kcontrol
, int event
)
1096 #ifdef CONFIG_HAVE_CLK
1097 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1098 return clk_enable(w
->clk
);
1100 clk_disable(w
->clk
);
1106 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1108 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1110 if (w
->power_checked
)
1111 return w
->new_power
;
1116 w
->new_power
= w
->power_check(w
);
1118 w
->power_checked
= true;
1120 return w
->new_power
;
1123 /* Generic check to see if a widget should be powered.
1125 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1129 DAPM_UPDATE_STAT(w
, power_checks
);
1131 in
= is_connected_input_ep(w
, NULL
);
1132 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1133 out
= is_connected_output_ep(w
, NULL
);
1134 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1135 return out
!= 0 && in
!= 0;
1138 static int dapm_dai_check_power(struct snd_soc_dapm_widget
*w
)
1140 DAPM_UPDATE_STAT(w
, power_checks
);
1145 return dapm_generic_check_power(w
);
1148 /* Check to see if an ADC has power */
1149 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
1153 DAPM_UPDATE_STAT(w
, power_checks
);
1156 in
= is_connected_input_ep(w
, NULL
);
1157 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1160 return dapm_generic_check_power(w
);
1164 /* Check to see if a DAC has power */
1165 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
1169 DAPM_UPDATE_STAT(w
, power_checks
);
1172 out
= is_connected_output_ep(w
, NULL
);
1173 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1176 return dapm_generic_check_power(w
);
1180 /* Check to see if a power supply is needed */
1181 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1183 struct snd_soc_dapm_path
*path
;
1185 DAPM_UPDATE_STAT(w
, power_checks
);
1187 /* Check if one of our outputs is connected */
1188 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1189 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1194 if (path
->connected
&&
1195 !path
->connected(path
->source
, path
->sink
))
1201 if (dapm_widget_power_check(path
->sink
))
1208 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1213 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1214 struct snd_soc_dapm_widget
*b
,
1222 sort
= dapm_down_seq
;
1224 if (sort
[a
->id
] != sort
[b
->id
])
1225 return sort
[a
->id
] - sort
[b
->id
];
1226 if (a
->subseq
!= b
->subseq
) {
1228 return a
->subseq
- b
->subseq
;
1230 return b
->subseq
- a
->subseq
;
1232 if (a
->reg
!= b
->reg
)
1233 return a
->reg
- b
->reg
;
1234 if (a
->dapm
!= b
->dapm
)
1235 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1240 /* Insert a widget in order into a DAPM power sequence. */
1241 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1242 struct list_head
*list
,
1245 struct snd_soc_dapm_widget
*w
;
1247 list_for_each_entry(w
, list
, power_list
)
1248 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1249 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1253 list_add_tail(&new_widget
->power_list
, list
);
1256 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
1257 struct snd_soc_dapm_widget
*w
, int event
)
1259 struct snd_soc_card
*card
= dapm
->card
;
1260 const char *ev_name
;
1264 case SND_SOC_DAPM_PRE_PMU
:
1265 ev_name
= "PRE_PMU";
1268 case SND_SOC_DAPM_POST_PMU
:
1269 ev_name
= "POST_PMU";
1272 case SND_SOC_DAPM_PRE_PMD
:
1273 ev_name
= "PRE_PMD";
1276 case SND_SOC_DAPM_POST_PMD
:
1277 ev_name
= "POST_PMD";
1285 if (w
->power
!= power
)
1288 if (w
->event
&& (w
->event_flags
& event
)) {
1289 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1291 trace_snd_soc_dapm_widget_event_start(w
, event
);
1292 ret
= w
->event(w
, NULL
, event
);
1293 trace_snd_soc_dapm_widget_event_done(w
, event
);
1295 dev_err(dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1296 ev_name
, w
->name
, ret
);
1300 /* Apply the coalesced changes from a DAPM sequence */
1301 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
1302 struct list_head
*pending
)
1304 struct snd_soc_card
*card
= dapm
->card
;
1305 struct snd_soc_dapm_widget
*w
;
1307 unsigned int value
= 0;
1308 unsigned int mask
= 0;
1309 unsigned int cur_mask
;
1311 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1314 list_for_each_entry(w
, pending
, power_list
) {
1315 cur_mask
= 1 << w
->shift
;
1316 BUG_ON(reg
!= w
->reg
);
1327 pop_dbg(dapm
->dev
, card
->pop_time
,
1328 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1329 w
->name
, reg
, value
, mask
);
1331 /* Check for events */
1332 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
1333 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
1337 /* Any widget will do, they should all be updating the
1340 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1343 pop_dbg(dapm
->dev
, card
->pop_time
,
1344 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1345 value
, mask
, reg
, card
->pop_time
);
1346 pop_wait(card
->pop_time
);
1347 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1350 list_for_each_entry(w
, pending
, power_list
) {
1351 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
1352 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
1356 /* Apply a DAPM power sequence.
1358 * We walk over a pre-sorted list of widgets to apply power to. In
1359 * order to minimise the number of writes to the device required
1360 * multiple widgets will be updated in a single write where possible.
1361 * Currently anything that requires more than a single write is not
1364 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
1365 struct list_head
*list
, int event
, bool power_up
)
1367 struct snd_soc_dapm_widget
*w
, *n
;
1370 int cur_subseq
= -1;
1371 int cur_reg
= SND_SOC_NOPM
;
1372 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1379 sort
= dapm_down_seq
;
1381 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1384 /* Do we need to apply any queued changes? */
1385 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1386 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1387 if (!list_empty(&pending
))
1388 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1390 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1391 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1392 if (sort
[i
] == cur_sort
)
1393 cur_dapm
->seq_notifier(cur_dapm
,
1398 INIT_LIST_HEAD(&pending
);
1400 cur_subseq
= INT_MIN
;
1401 cur_reg
= SND_SOC_NOPM
;
1406 case snd_soc_dapm_pre
:
1408 list_for_each_entry_safe_continue(w
, n
, list
,
1411 if (event
== SND_SOC_DAPM_STREAM_START
)
1413 NULL
, SND_SOC_DAPM_PRE_PMU
);
1414 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1416 NULL
, SND_SOC_DAPM_PRE_PMD
);
1419 case snd_soc_dapm_post
:
1421 list_for_each_entry_safe_continue(w
, n
, list
,
1424 if (event
== SND_SOC_DAPM_STREAM_START
)
1426 NULL
, SND_SOC_DAPM_POST_PMU
);
1427 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1429 NULL
, SND_SOC_DAPM_POST_PMD
);
1433 /* Queue it up for application */
1434 cur_sort
= sort
[w
->id
];
1435 cur_subseq
= w
->subseq
;
1438 list_move(&w
->power_list
, &pending
);
1443 dev_err(w
->dapm
->dev
,
1444 "ASoC: Failed to apply widget power: %d\n", ret
);
1447 if (!list_empty(&pending
))
1448 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1450 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1451 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1452 if (sort
[i
] == cur_sort
)
1453 cur_dapm
->seq_notifier(cur_dapm
,
1458 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1460 struct snd_soc_dapm_update
*update
= dapm
->update
;
1461 struct snd_soc_dapm_widget
*w
;
1470 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1471 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1473 dev_err(dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1477 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1480 dev_err(dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1484 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1485 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1487 dev_err(dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1492 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1493 * they're changing state.
1495 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1497 struct snd_soc_dapm_context
*d
= data
;
1500 /* If we're off and we're not supposed to be go into STANDBY */
1501 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1502 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1504 pm_runtime_get_sync(d
->dev
);
1506 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1509 "ASoC: Failed to turn on bias: %d\n", ret
);
1512 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1513 if (d
->bias_level
!= d
->target_bias_level
) {
1514 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1517 "ASoC: Failed to prepare bias: %d\n", ret
);
1521 /* Async callback run prior to DAPM sequences - brings to their final
1524 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1526 struct snd_soc_dapm_context
*d
= data
;
1529 /* If we just powered the last thing off drop to standby bias */
1530 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1531 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1532 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1533 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1535 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1539 /* If we're in standby and can support bias off then do that */
1540 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1541 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1542 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1544 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1548 pm_runtime_put(d
->dev
);
1551 /* If we just powered up then move to active bias */
1552 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1553 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1554 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1556 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1561 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1562 bool power
, bool connect
)
1564 /* If a connection is being made or broken then that update
1565 * will have marked the peer dirty, otherwise the widgets are
1566 * not connected and this update has no impact. */
1570 /* If the peer is already in the state we're moving to then we
1571 * won't have an impact on it. */
1572 if (power
!= peer
->power
)
1573 dapm_mark_dirty(peer
, "peer state change");
1576 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1577 struct list_head
*up_list
,
1578 struct list_head
*down_list
)
1580 struct snd_soc_dapm_path
*path
;
1582 if (w
->power
== power
)
1585 trace_snd_soc_dapm_widget_power(w
, power
);
1587 /* If we changed our power state perhaps our neigbours changed
1590 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1592 dapm_widget_set_peer_power(path
->source
, power
,
1597 case snd_soc_dapm_supply
:
1598 case snd_soc_dapm_regulator_supply
:
1599 case snd_soc_dapm_clock_supply
:
1600 /* Supplies can't affect their outputs, only their inputs */
1603 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1605 dapm_widget_set_peer_power(path
->sink
, power
,
1613 dapm_seq_insert(w
, up_list
, true);
1615 dapm_seq_insert(w
, down_list
, false);
1620 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1621 struct list_head
*up_list
,
1622 struct list_head
*down_list
)
1627 case snd_soc_dapm_pre
:
1628 dapm_seq_insert(w
, down_list
, false);
1630 case snd_soc_dapm_post
:
1631 dapm_seq_insert(w
, up_list
, true);
1635 power
= dapm_widget_power_check(w
);
1637 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1643 * Scan each dapm widget for complete audio path.
1644 * A complete path is a route that has valid endpoints i.e.:-
1646 * o DAC to output pin.
1647 * o Input Pin to ADC.
1648 * o Input pin to Output pin (bypass, sidetone)
1649 * o DAC to ADC (loopback).
1651 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1653 struct snd_soc_card
*card
= dapm
->card
;
1654 struct snd_soc_dapm_widget
*w
;
1655 struct snd_soc_dapm_context
*d
;
1657 LIST_HEAD(down_list
);
1658 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1659 enum snd_soc_bias_level bias
;
1661 trace_snd_soc_dapm_start(card
);
1663 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1664 if (d
->idle_bias_off
)
1665 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1667 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1672 /* Check which widgets we need to power and store them in
1673 * lists indicating if they should be powered up or down. We
1674 * only check widgets that have been flagged as dirty but note
1675 * that new widgets may be added to the dirty list while we
1678 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1679 dapm_power_one_widget(w
, &up_list
, &down_list
);
1682 list_for_each_entry(w
, &card
->widgets
, list
) {
1684 case snd_soc_dapm_pre
:
1685 case snd_soc_dapm_post
:
1686 /* These widgets always need to be powered */
1689 list_del_init(&w
->dirty
);
1696 /* Supplies and micbiases only bring the
1697 * context up to STANDBY as unless something
1698 * else is active and passing audio they
1699 * generally don't require full power. Signal
1700 * generators are virtual pins and have no
1701 * power impact themselves.
1704 case snd_soc_dapm_siggen
:
1706 case snd_soc_dapm_supply
:
1707 case snd_soc_dapm_regulator_supply
:
1708 case snd_soc_dapm_clock_supply
:
1709 case snd_soc_dapm_micbias
:
1710 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1711 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1714 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1721 /* Force all contexts in the card to the same bias state if
1722 * they're not ground referenced.
1724 bias
= SND_SOC_BIAS_OFF
;
1725 list_for_each_entry(d
, &card
->dapm_list
, list
)
1726 if (d
->target_bias_level
> bias
)
1727 bias
= d
->target_bias_level
;
1728 list_for_each_entry(d
, &card
->dapm_list
, list
)
1729 if (!d
->idle_bias_off
)
1730 d
->target_bias_level
= bias
;
1732 trace_snd_soc_dapm_walk_done(card
);
1734 /* Run all the bias changes in parallel */
1735 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1736 async_schedule_domain(dapm_pre_sequence_async
, d
,
1738 async_synchronize_full_domain(&async_domain
);
1740 /* Power down widgets first; try to avoid amplifying pops. */
1741 dapm_seq_run(dapm
, &down_list
, event
, false);
1743 dapm_widget_update(dapm
);
1746 dapm_seq_run(dapm
, &up_list
, event
, true);
1748 /* Run all the bias changes in parallel */
1749 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1750 async_schedule_domain(dapm_post_sequence_async
, d
,
1752 async_synchronize_full_domain(&async_domain
);
1754 /* do we need to notify any clients that DAPM event is complete */
1755 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1756 if (d
->stream_event
)
1757 d
->stream_event(d
, event
);
1760 pop_dbg(dapm
->dev
, card
->pop_time
,
1761 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1762 pop_wait(card
->pop_time
);
1764 trace_snd_soc_dapm_done(card
);
1769 #ifdef CONFIG_DEBUG_FS
1770 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1771 char __user
*user_buf
,
1772 size_t count
, loff_t
*ppos
)
1774 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1778 struct snd_soc_dapm_path
*p
= NULL
;
1780 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1784 in
= is_connected_input_ep(w
, NULL
);
1785 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1786 out
= is_connected_output_ep(w
, NULL
);
1787 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1789 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1790 w
->name
, w
->power
? "On" : "Off",
1791 w
->force
? " (forced)" : "", in
, out
);
1794 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1795 " - R%d(0x%x) bit %d",
1796 w
->reg
, w
->reg
, w
->shift
);
1798 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1801 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1803 w
->active
? "active" : "inactive");
1805 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1806 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1810 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1811 " in \"%s\" \"%s\"\n",
1812 p
->name
? p
->name
: "static",
1815 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1816 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1820 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1821 " out \"%s\" \"%s\"\n",
1822 p
->name
? p
->name
: "static",
1826 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1832 static const struct file_operations dapm_widget_power_fops
= {
1833 .open
= simple_open
,
1834 .read
= dapm_widget_power_read_file
,
1835 .llseek
= default_llseek
,
1838 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1839 size_t count
, loff_t
*ppos
)
1841 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1844 switch (dapm
->bias_level
) {
1845 case SND_SOC_BIAS_ON
:
1848 case SND_SOC_BIAS_PREPARE
:
1849 level
= "Prepare\n";
1851 case SND_SOC_BIAS_STANDBY
:
1852 level
= "Standby\n";
1854 case SND_SOC_BIAS_OFF
:
1859 level
= "Unknown\n";
1863 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1867 static const struct file_operations dapm_bias_fops
= {
1868 .open
= simple_open
,
1869 .read
= dapm_bias_read_file
,
1870 .llseek
= default_llseek
,
1873 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1874 struct dentry
*parent
)
1878 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1880 if (!dapm
->debugfs_dapm
) {
1882 "ASoC: Failed to create DAPM debugfs directory\n");
1886 d
= debugfs_create_file("bias_level", 0444,
1887 dapm
->debugfs_dapm
, dapm
,
1891 "ASoC: Failed to create bias level debugfs file\n");
1894 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1896 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1899 if (!dapm
->debugfs_dapm
|| !w
->name
)
1902 d
= debugfs_create_file(w
->name
, 0444,
1903 dapm
->debugfs_dapm
, w
,
1904 &dapm_widget_power_fops
);
1906 dev_warn(w
->dapm
->dev
,
1907 "ASoC: Failed to create %s debugfs file\n",
1911 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1913 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1917 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1918 struct dentry
*parent
)
1922 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1926 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1932 /* test and update the power status of a mux widget */
1933 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1934 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1936 struct snd_soc_dapm_path
*path
;
1939 if (widget
->id
!= snd_soc_dapm_mux
&&
1940 widget
->id
!= snd_soc_dapm_virt_mux
&&
1941 widget
->id
!= snd_soc_dapm_value_mux
)
1944 /* find dapm widget path assoc with kcontrol */
1945 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1946 if (path
->kcontrol
!= kcontrol
)
1949 if (!path
->name
|| !e
->texts
[mux
])
1953 /* we now need to match the string in the enum to the path */
1954 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
1955 path
->connect
= 1; /* new connection */
1956 dapm_mark_dirty(path
->source
, "mux connection");
1959 dapm_mark_dirty(path
->source
,
1960 "mux disconnection");
1961 path
->connect
= 0; /* old connection must be powered down */
1966 dapm_mark_dirty(widget
, "mux change");
1967 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1973 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1974 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1976 struct snd_soc_card
*card
= widget
->dapm
->card
;
1979 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1980 ret
= soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
1981 mutex_unlock(&card
->dapm_mutex
);
1983 soc_dpcm_runtime_update(widget
);
1986 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
1988 /* test and update the power status of a mixer or switch widget */
1989 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1990 struct snd_kcontrol
*kcontrol
, int connect
)
1992 struct snd_soc_dapm_path
*path
;
1995 if (widget
->id
!= snd_soc_dapm_mixer
&&
1996 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1997 widget
->id
!= snd_soc_dapm_switch
)
2000 /* find dapm widget path assoc with kcontrol */
2001 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
2002 if (path
->kcontrol
!= kcontrol
)
2005 /* found, now check type */
2007 path
->connect
= connect
;
2008 dapm_mark_dirty(path
->source
, "mixer connection");
2012 dapm_mark_dirty(widget
, "mixer update");
2013 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
2019 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
2020 struct snd_kcontrol
*kcontrol
, int connect
)
2022 struct snd_soc_card
*card
= widget
->dapm
->card
;
2025 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2026 ret
= soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2027 mutex_unlock(&card
->dapm_mutex
);
2029 soc_dpcm_runtime_update(widget
);
2032 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2034 /* show dapm widget status in sys fs */
2035 static ssize_t
dapm_widget_show(struct device
*dev
,
2036 struct device_attribute
*attr
, char *buf
)
2038 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2039 struct snd_soc_codec
*codec
=rtd
->codec
;
2040 struct snd_soc_dapm_widget
*w
;
2042 char *state
= "not set";
2044 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
2045 if (w
->dapm
!= &codec
->dapm
)
2048 /* only display widgets that burnm power */
2050 case snd_soc_dapm_hp
:
2051 case snd_soc_dapm_mic
:
2052 case snd_soc_dapm_spk
:
2053 case snd_soc_dapm_line
:
2054 case snd_soc_dapm_micbias
:
2055 case snd_soc_dapm_dac
:
2056 case snd_soc_dapm_adc
:
2057 case snd_soc_dapm_pga
:
2058 case snd_soc_dapm_out_drv
:
2059 case snd_soc_dapm_mixer
:
2060 case snd_soc_dapm_mixer_named_ctl
:
2061 case snd_soc_dapm_supply
:
2062 case snd_soc_dapm_regulator_supply
:
2063 case snd_soc_dapm_clock_supply
:
2065 count
+= sprintf(buf
+ count
, "%s: %s\n",
2066 w
->name
, w
->power
? "On":"Off");
2073 switch (codec
->dapm
.bias_level
) {
2074 case SND_SOC_BIAS_ON
:
2077 case SND_SOC_BIAS_PREPARE
:
2080 case SND_SOC_BIAS_STANDBY
:
2083 case SND_SOC_BIAS_OFF
:
2087 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2092 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2094 int snd_soc_dapm_sys_add(struct device
*dev
)
2096 return device_create_file(dev
, &dev_attr_dapm_widget
);
2099 static void snd_soc_dapm_sys_remove(struct device
*dev
)
2101 device_remove_file(dev
, &dev_attr_dapm_widget
);
2104 /* free all dapm widgets and resources */
2105 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2107 struct snd_soc_dapm_widget
*w
, *next_w
;
2108 struct snd_soc_dapm_path
*p
, *next_p
;
2110 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2111 if (w
->dapm
!= dapm
)
2115 * remove source and sink paths associated to this widget.
2116 * While removing the path, remove reference to it from both
2117 * source and sink widgets so that path is removed only once.
2119 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
2120 list_del(&p
->list_sink
);
2121 list_del(&p
->list_source
);
2123 kfree(p
->long_name
);
2126 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
2127 list_del(&p
->list_sink
);
2128 list_del(&p
->list_source
);
2130 kfree(p
->long_name
);
2133 kfree(w
->kcontrols
);
2139 static struct snd_soc_dapm_widget
*dapm_find_widget(
2140 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2141 bool search_other_contexts
)
2143 struct snd_soc_dapm_widget
*w
;
2144 struct snd_soc_dapm_widget
*fallback
= NULL
;
2146 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2147 if (!strcmp(w
->name
, pin
)) {
2148 if (w
->dapm
== dapm
)
2155 if (search_other_contexts
)
2161 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2162 const char *pin
, int status
)
2164 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2167 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2171 if (w
->connected
!= status
)
2172 dapm_mark_dirty(w
, "pin configuration");
2174 w
->connected
= status
;
2182 * snd_soc_dapm_sync - scan and power dapm paths
2183 * @dapm: DAPM context
2185 * Walks all dapm audio paths and powers widgets according to their
2186 * stream or path usage.
2188 * Returns 0 for success.
2190 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2195 * Suppress early reports (eg, jacks syncing their state) to avoid
2196 * silly DAPM runs during card startup.
2198 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2201 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2202 ret
= dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2203 mutex_unlock(&dapm
->card
->dapm_mutex
);
2206 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2208 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2209 const struct snd_soc_dapm_route
*route
)
2211 struct snd_soc_dapm_path
*path
;
2212 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2213 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2215 const char *control
= route
->control
;
2217 char prefixed_sink
[80];
2218 char prefixed_source
[80];
2221 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2222 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2223 dapm
->codec
->name_prefix
, route
->sink
);
2224 sink
= prefixed_sink
;
2225 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2226 dapm
->codec
->name_prefix
, route
->source
);
2227 source
= prefixed_source
;
2230 source
= route
->source
;
2234 * find src and dest widgets over all widgets but favor a widget from
2235 * current DAPM context
2237 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2238 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2240 if (w
->dapm
== dapm
)
2244 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2246 if (w
->dapm
== dapm
)
2250 /* use widget from another DAPM context if not found from this */
2256 if (wsource
== NULL
) {
2257 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2261 if (wsink
== NULL
) {
2262 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2267 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2271 path
->source
= wsource
;
2273 path
->connected
= route
->connected
;
2274 INIT_LIST_HEAD(&path
->list
);
2275 INIT_LIST_HEAD(&path
->list_source
);
2276 INIT_LIST_HEAD(&path
->list_sink
);
2278 /* check for external widgets */
2279 if (wsink
->id
== snd_soc_dapm_input
) {
2280 if (wsource
->id
== snd_soc_dapm_micbias
||
2281 wsource
->id
== snd_soc_dapm_mic
||
2282 wsource
->id
== snd_soc_dapm_line
||
2283 wsource
->id
== snd_soc_dapm_output
)
2286 if (wsource
->id
== snd_soc_dapm_output
) {
2287 if (wsink
->id
== snd_soc_dapm_spk
||
2288 wsink
->id
== snd_soc_dapm_hp
||
2289 wsink
->id
== snd_soc_dapm_line
||
2290 wsink
->id
== snd_soc_dapm_input
)
2294 /* connect static paths */
2295 if (control
== NULL
) {
2296 list_add(&path
->list
, &dapm
->card
->paths
);
2297 list_add(&path
->list_sink
, &wsink
->sources
);
2298 list_add(&path
->list_source
, &wsource
->sinks
);
2303 /* connect dynamic paths */
2304 switch (wsink
->id
) {
2305 case snd_soc_dapm_adc
:
2306 case snd_soc_dapm_dac
:
2307 case snd_soc_dapm_pga
:
2308 case snd_soc_dapm_out_drv
:
2309 case snd_soc_dapm_input
:
2310 case snd_soc_dapm_output
:
2311 case snd_soc_dapm_siggen
:
2312 case snd_soc_dapm_micbias
:
2313 case snd_soc_dapm_vmid
:
2314 case snd_soc_dapm_pre
:
2315 case snd_soc_dapm_post
:
2316 case snd_soc_dapm_supply
:
2317 case snd_soc_dapm_regulator_supply
:
2318 case snd_soc_dapm_clock_supply
:
2319 case snd_soc_dapm_aif_in
:
2320 case snd_soc_dapm_aif_out
:
2321 case snd_soc_dapm_dai
:
2322 case snd_soc_dapm_dai_link
:
2323 list_add(&path
->list
, &dapm
->card
->paths
);
2324 list_add(&path
->list_sink
, &wsink
->sources
);
2325 list_add(&path
->list_source
, &wsource
->sinks
);
2328 case snd_soc_dapm_mux
:
2329 case snd_soc_dapm_virt_mux
:
2330 case snd_soc_dapm_value_mux
:
2331 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2332 &wsink
->kcontrol_news
[0]);
2336 case snd_soc_dapm_switch
:
2337 case snd_soc_dapm_mixer
:
2338 case snd_soc_dapm_mixer_named_ctl
:
2339 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2343 case snd_soc_dapm_hp
:
2344 case snd_soc_dapm_mic
:
2345 case snd_soc_dapm_line
:
2346 case snd_soc_dapm_spk
:
2347 list_add(&path
->list
, &dapm
->card
->paths
);
2348 list_add(&path
->list_sink
, &wsink
->sources
);
2349 list_add(&path
->list_source
, &wsource
->sinks
);
2354 dapm_mark_dirty(wsource
, "Route added");
2355 dapm_mark_dirty(wsink
, "Route added");
2360 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2361 source
, control
, sink
);
2366 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2367 const struct snd_soc_dapm_route
*route
)
2369 struct snd_soc_dapm_path
*path
, *p
;
2372 char prefixed_sink
[80];
2373 char prefixed_source
[80];
2375 if (route
->control
) {
2377 "ASoC: Removal of routes with controls not supported\n");
2381 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2382 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2383 dapm
->codec
->name_prefix
, route
->sink
);
2384 sink
= prefixed_sink
;
2385 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2386 dapm
->codec
->name_prefix
, route
->source
);
2387 source
= prefixed_source
;
2390 source
= route
->source
;
2394 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2395 if (strcmp(p
->source
->name
, source
) != 0)
2397 if (strcmp(p
->sink
->name
, sink
) != 0)
2404 dapm_mark_dirty(path
->source
, "Route removed");
2405 dapm_mark_dirty(path
->sink
, "Route removed");
2407 list_del(&path
->list
);
2408 list_del(&path
->list_sink
);
2409 list_del(&path
->list_source
);
2412 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
2420 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2421 * @dapm: DAPM context
2422 * @route: audio routes
2423 * @num: number of routes
2425 * Connects 2 dapm widgets together via a named audio path. The sink is
2426 * the widget receiving the audio signal, whilst the source is the sender
2427 * of the audio signal.
2429 * Returns 0 for success else error. On error all resources can be freed
2430 * with a call to snd_soc_card_free().
2432 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2433 const struct snd_soc_dapm_route
*route
, int num
)
2437 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2438 for (i
= 0; i
< num
; i
++) {
2439 r
= snd_soc_dapm_add_route(dapm
, route
);
2441 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
2443 route
->control
? route
->control
: "direct",
2449 mutex_unlock(&dapm
->card
->dapm_mutex
);
2453 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2456 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2457 * @dapm: DAPM context
2458 * @route: audio routes
2459 * @num: number of routes
2461 * Removes routes from the DAPM context.
2463 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2464 const struct snd_soc_dapm_route
*route
, int num
)
2468 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2469 for (i
= 0; i
< num
; i
++) {
2470 snd_soc_dapm_del_route(dapm
, route
);
2473 mutex_unlock(&dapm
->card
->dapm_mutex
);
2477 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2479 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2480 const struct snd_soc_dapm_route
*route
)
2482 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2485 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2488 struct snd_soc_dapm_path
*path
;
2492 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
2498 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
2503 if (route
->control
|| route
->connected
)
2504 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
2505 route
->source
, route
->sink
);
2507 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2508 if (path
->sink
== sink
) {
2515 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
2516 route
->source
, route
->sink
);
2518 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
2519 count
, route
->source
, route
->sink
);
2525 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2526 * @dapm: DAPM context
2527 * @route: audio routes
2528 * @num: number of routes
2530 * Mark existing routes matching those specified in the passed array
2531 * as being weak, meaning that they are ignored for the purpose of
2532 * power decisions. The main intended use case is for sidetone paths
2533 * which couple audio between other independent paths if they are both
2534 * active in order to make the combination work better at the user
2535 * level but which aren't intended to be "used".
2537 * Note that CODEC drivers should not use this as sidetone type paths
2538 * can frequently also be used as bypass paths.
2540 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2541 const struct snd_soc_dapm_route
*route
, int num
)
2546 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2547 for (i
= 0; i
< num
; i
++) {
2548 err
= snd_soc_dapm_weak_route(dapm
, route
);
2553 mutex_unlock(&dapm
->card
->dapm_mutex
);
2557 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2560 * snd_soc_dapm_new_widgets - add new dapm widgets
2561 * @dapm: DAPM context
2563 * Checks the codec for any new dapm widgets and creates them if found.
2565 * Returns 0 for success.
2567 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
2569 struct snd_soc_dapm_widget
*w
;
2572 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2574 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2579 if (w
->num_kcontrols
) {
2580 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2581 sizeof(struct snd_kcontrol
*),
2583 if (!w
->kcontrols
) {
2584 mutex_unlock(&dapm
->card
->dapm_mutex
);
2590 case snd_soc_dapm_switch
:
2591 case snd_soc_dapm_mixer
:
2592 case snd_soc_dapm_mixer_named_ctl
:
2595 case snd_soc_dapm_mux
:
2596 case snd_soc_dapm_virt_mux
:
2597 case snd_soc_dapm_value_mux
:
2600 case snd_soc_dapm_pga
:
2601 case snd_soc_dapm_out_drv
:
2608 /* Read the initial power state from the device */
2610 val
= soc_widget_read(w
, w
->reg
);
2611 val
&= 1 << w
->shift
;
2621 dapm_mark_dirty(w
, "new widget");
2622 dapm_debugfs_add_widget(w
);
2625 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2626 mutex_unlock(&dapm
->card
->dapm_mutex
);
2629 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2632 * snd_soc_dapm_get_volsw - dapm mixer get callback
2633 * @kcontrol: mixer control
2634 * @ucontrol: control element information
2636 * Callback to get the value of a dapm mixer control.
2638 * Returns 0 for success.
2640 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2641 struct snd_ctl_elem_value
*ucontrol
)
2643 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2644 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2645 struct soc_mixer_control
*mc
=
2646 (struct soc_mixer_control
*)kcontrol
->private_value
;
2647 unsigned int reg
= mc
->reg
;
2648 unsigned int shift
= mc
->shift
;
2650 unsigned int mask
= (1 << fls(max
)) - 1;
2651 unsigned int invert
= mc
->invert
;
2653 if (snd_soc_volsw_is_stereo(mc
))
2654 dev_warn(widget
->dapm
->dev
,
2655 "ASoC: Control '%s' is stereo, which is not supported\n",
2658 ucontrol
->value
.integer
.value
[0] =
2659 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2661 ucontrol
->value
.integer
.value
[0] =
2662 max
- ucontrol
->value
.integer
.value
[0];
2666 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2669 * snd_soc_dapm_put_volsw - dapm mixer set callback
2670 * @kcontrol: mixer control
2671 * @ucontrol: control element information
2673 * Callback to set the value of a dapm mixer control.
2675 * Returns 0 for success.
2677 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2678 struct snd_ctl_elem_value
*ucontrol
)
2680 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2681 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2682 struct snd_soc_codec
*codec
= widget
->codec
;
2683 struct snd_soc_card
*card
= codec
->card
;
2684 struct soc_mixer_control
*mc
=
2685 (struct soc_mixer_control
*)kcontrol
->private_value
;
2686 unsigned int reg
= mc
->reg
;
2687 unsigned int shift
= mc
->shift
;
2689 unsigned int mask
= (1 << fls(max
)) - 1;
2690 unsigned int invert
= mc
->invert
;
2692 int connect
, change
;
2693 struct snd_soc_dapm_update update
;
2696 if (snd_soc_volsw_is_stereo(mc
))
2697 dev_warn(widget
->dapm
->dev
,
2698 "ASoC: Control '%s' is stereo, which is not supported\n",
2701 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2706 mask
= mask
<< shift
;
2709 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2711 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2713 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2714 widget
= wlist
->widgets
[wi
];
2716 widget
->value
= val
;
2718 update
.kcontrol
= kcontrol
;
2719 update
.widget
= widget
;
2723 widget
->dapm
->update
= &update
;
2725 soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2727 widget
->dapm
->update
= NULL
;
2731 mutex_unlock(&card
->dapm_mutex
);
2734 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2737 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2738 * @kcontrol: mixer control
2739 * @ucontrol: control element information
2741 * Callback to get the value of a dapm enumerated double mixer control.
2743 * Returns 0 for success.
2745 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2746 struct snd_ctl_elem_value
*ucontrol
)
2748 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2749 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2750 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2753 val
= snd_soc_read(widget
->codec
, e
->reg
);
2754 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & e
->mask
;
2755 if (e
->shift_l
!= e
->shift_r
)
2756 ucontrol
->value
.enumerated
.item
[1] =
2757 (val
>> e
->shift_r
) & e
->mask
;
2761 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2764 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2765 * @kcontrol: mixer control
2766 * @ucontrol: control element information
2768 * Callback to set the value of a dapm enumerated double mixer control.
2770 * Returns 0 for success.
2772 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2773 struct snd_ctl_elem_value
*ucontrol
)
2775 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2776 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2777 struct snd_soc_codec
*codec
= widget
->codec
;
2778 struct snd_soc_card
*card
= codec
->card
;
2779 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2780 unsigned int val
, mux
, change
;
2782 struct snd_soc_dapm_update update
;
2785 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2787 mux
= ucontrol
->value
.enumerated
.item
[0];
2788 val
= mux
<< e
->shift_l
;
2789 mask
= e
->mask
<< e
->shift_l
;
2790 if (e
->shift_l
!= e
->shift_r
) {
2791 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2793 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2794 mask
|= e
->mask
<< e
->shift_r
;
2797 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2799 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2801 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2802 widget
= wlist
->widgets
[wi
];
2804 widget
->value
= val
;
2806 update
.kcontrol
= kcontrol
;
2807 update
.widget
= widget
;
2808 update
.reg
= e
->reg
;
2811 widget
->dapm
->update
= &update
;
2813 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2815 widget
->dapm
->update
= NULL
;
2819 mutex_unlock(&card
->dapm_mutex
);
2822 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2825 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2826 * @kcontrol: mixer control
2827 * @ucontrol: control element information
2829 * Returns 0 for success.
2831 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2832 struct snd_ctl_elem_value
*ucontrol
)
2834 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2835 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2837 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2841 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2844 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2845 * @kcontrol: mixer control
2846 * @ucontrol: control element information
2848 * Returns 0 for success.
2850 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2851 struct snd_ctl_elem_value
*ucontrol
)
2853 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2854 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2855 struct snd_soc_codec
*codec
= widget
->codec
;
2856 struct snd_soc_card
*card
= codec
->card
;
2857 struct soc_enum
*e
=
2858 (struct soc_enum
*)kcontrol
->private_value
;
2863 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2866 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2868 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2870 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2871 widget
= wlist
->widgets
[wi
];
2873 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2875 soc_dapm_mux_update_power(widget
, kcontrol
, widget
->value
, e
);
2879 mutex_unlock(&card
->dapm_mutex
);
2882 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2885 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2887 * @kcontrol: mixer control
2888 * @ucontrol: control element information
2890 * Callback to get the value of a dapm semi enumerated double mixer control.
2892 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2893 * used for handling bitfield coded enumeration for example.
2895 * Returns 0 for success.
2897 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2898 struct snd_ctl_elem_value
*ucontrol
)
2900 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2901 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2902 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2903 unsigned int reg_val
, val
, mux
;
2905 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2906 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2907 for (mux
= 0; mux
< e
->max
; mux
++) {
2908 if (val
== e
->values
[mux
])
2911 ucontrol
->value
.enumerated
.item
[0] = mux
;
2912 if (e
->shift_l
!= e
->shift_r
) {
2913 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2914 for (mux
= 0; mux
< e
->max
; mux
++) {
2915 if (val
== e
->values
[mux
])
2918 ucontrol
->value
.enumerated
.item
[1] = mux
;
2923 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2926 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2928 * @kcontrol: mixer control
2929 * @ucontrol: control element information
2931 * Callback to set the value of a dapm semi enumerated double mixer control.
2933 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2934 * used for handling bitfield coded enumeration for example.
2936 * Returns 0 for success.
2938 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2939 struct snd_ctl_elem_value
*ucontrol
)
2941 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2942 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2943 struct snd_soc_codec
*codec
= widget
->codec
;
2944 struct snd_soc_card
*card
= codec
->card
;
2945 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2946 unsigned int val
, mux
, change
;
2948 struct snd_soc_dapm_update update
;
2951 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2953 mux
= ucontrol
->value
.enumerated
.item
[0];
2954 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2955 mask
= e
->mask
<< e
->shift_l
;
2956 if (e
->shift_l
!= e
->shift_r
) {
2957 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2959 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2960 mask
|= e
->mask
<< e
->shift_r
;
2963 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2965 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2967 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2968 widget
= wlist
->widgets
[wi
];
2970 widget
->value
= val
;
2972 update
.kcontrol
= kcontrol
;
2973 update
.widget
= widget
;
2974 update
.reg
= e
->reg
;
2977 widget
->dapm
->update
= &update
;
2979 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2981 widget
->dapm
->update
= NULL
;
2985 mutex_unlock(&card
->dapm_mutex
);
2988 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2991 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2993 * @kcontrol: mixer control
2994 * @uinfo: control element information
2996 * Callback to provide information about a pin switch control.
2998 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2999 struct snd_ctl_elem_info
*uinfo
)
3001 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3003 uinfo
->value
.integer
.min
= 0;
3004 uinfo
->value
.integer
.max
= 1;
3008 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3011 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3013 * @kcontrol: mixer control
3016 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3017 struct snd_ctl_elem_value
*ucontrol
)
3019 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3020 const char *pin
= (const char *)kcontrol
->private_value
;
3022 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3024 ucontrol
->value
.integer
.value
[0] =
3025 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3027 mutex_unlock(&card
->dapm_mutex
);
3031 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3034 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3036 * @kcontrol: mixer control
3039 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3040 struct snd_ctl_elem_value
*ucontrol
)
3042 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3043 const char *pin
= (const char *)kcontrol
->private_value
;
3045 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3047 if (ucontrol
->value
.integer
.value
[0])
3048 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3050 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3052 mutex_unlock(&card
->dapm_mutex
);
3054 snd_soc_dapm_sync(&card
->dapm
);
3057 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3059 static struct snd_soc_dapm_widget
*
3060 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3061 const struct snd_soc_dapm_widget
*widget
)
3063 struct snd_soc_dapm_widget
*w
;
3067 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3071 case snd_soc_dapm_regulator_supply
:
3072 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3073 if (IS_ERR(w
->regulator
)) {
3074 ret
= PTR_ERR(w
->regulator
);
3075 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3080 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3081 ret
= regulator_allow_bypass(w
->regulator
, true);
3083 dev_warn(w
->dapm
->dev
,
3084 "ASoC: Failed to unbypass %s: %d\n",
3088 case snd_soc_dapm_clock_supply
:
3089 #ifdef CONFIG_CLKDEV_LOOKUP
3090 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3091 if (IS_ERR(w
->clk
)) {
3092 ret
= PTR_ERR(w
->clk
);
3093 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3105 name_len
= strlen(widget
->name
) + 1;
3106 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3107 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
3108 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
3109 if (w
->name
== NULL
) {
3113 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3114 snprintf((char *)w
->name
, name_len
, "%s %s",
3115 dapm
->codec
->name_prefix
, widget
->name
);
3117 snprintf((char *)w
->name
, name_len
, "%s", widget
->name
);
3120 case snd_soc_dapm_switch
:
3121 case snd_soc_dapm_mixer
:
3122 case snd_soc_dapm_mixer_named_ctl
:
3123 w
->power_check
= dapm_generic_check_power
;
3125 case snd_soc_dapm_mux
:
3126 case snd_soc_dapm_virt_mux
:
3127 case snd_soc_dapm_value_mux
:
3128 w
->power_check
= dapm_generic_check_power
;
3130 case snd_soc_dapm_adc
:
3131 case snd_soc_dapm_aif_out
:
3132 w
->power_check
= dapm_adc_check_power
;
3134 case snd_soc_dapm_dac
:
3135 case snd_soc_dapm_aif_in
:
3136 w
->power_check
= dapm_dac_check_power
;
3138 case snd_soc_dapm_pga
:
3139 case snd_soc_dapm_out_drv
:
3140 case snd_soc_dapm_input
:
3141 case snd_soc_dapm_output
:
3142 case snd_soc_dapm_micbias
:
3143 case snd_soc_dapm_spk
:
3144 case snd_soc_dapm_hp
:
3145 case snd_soc_dapm_mic
:
3146 case snd_soc_dapm_line
:
3147 case snd_soc_dapm_dai_link
:
3148 w
->power_check
= dapm_generic_check_power
;
3150 case snd_soc_dapm_supply
:
3151 case snd_soc_dapm_regulator_supply
:
3152 case snd_soc_dapm_clock_supply
:
3153 w
->power_check
= dapm_supply_check_power
;
3155 case snd_soc_dapm_dai
:
3156 w
->power_check
= dapm_dai_check_power
;
3159 w
->power_check
= dapm_always_on_check_power
;
3164 w
->codec
= dapm
->codec
;
3165 w
->platform
= dapm
->platform
;
3166 INIT_LIST_HEAD(&w
->sources
);
3167 INIT_LIST_HEAD(&w
->sinks
);
3168 INIT_LIST_HEAD(&w
->list
);
3169 INIT_LIST_HEAD(&w
->dirty
);
3170 list_add(&w
->list
, &dapm
->card
->widgets
);
3172 /* machine layer set ups unconnected pins and insertions */
3178 * snd_soc_dapm_new_controls - create new dapm controls
3179 * @dapm: DAPM context
3180 * @widget: widget array
3181 * @num: number of widgets
3183 * Creates new DAPM controls based upon the templates.
3185 * Returns 0 for success else error.
3187 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3188 const struct snd_soc_dapm_widget
*widget
,
3191 struct snd_soc_dapm_widget
*w
;
3195 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3196 for (i
= 0; i
< num
; i
++) {
3197 w
= snd_soc_dapm_new_control(dapm
, widget
);
3200 "ASoC: Failed to create DAPM control %s\n",
3207 mutex_unlock(&dapm
->card
->dapm_mutex
);
3210 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3212 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3213 struct snd_kcontrol
*kcontrol
, int event
)
3215 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3216 struct snd_soc_dai
*source
, *sink
;
3217 const struct snd_soc_pcm_stream
*config
= w
->params
;
3218 struct snd_pcm_substream substream
;
3219 struct snd_pcm_hw_params
*params
= NULL
;
3224 BUG_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
));
3226 /* We only support a single source and sink, pick the first */
3227 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3229 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3232 BUG_ON(!source_p
|| !sink_p
);
3233 BUG_ON(!sink_p
->source
|| !source_p
->sink
);
3234 BUG_ON(!source_p
->source
|| !sink_p
->sink
);
3236 source
= source_p
->source
->priv
;
3237 sink
= sink_p
->sink
->priv
;
3239 /* Be a little careful as we don't want to overflow the mask array */
3240 if (config
->formats
) {
3241 fmt
= ffs(config
->formats
) - 1;
3243 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3248 /* Currently very limited parameter selection */
3249 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3254 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3256 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3258 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3261 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3262 = config
->channels_min
;
3263 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3264 = config
->channels_max
;
3266 memset(&substream
, 0, sizeof(substream
));
3269 case SND_SOC_DAPM_PRE_PMU
:
3270 if (source
->driver
->ops
&& source
->driver
->ops
->hw_params
) {
3271 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3272 ret
= source
->driver
->ops
->hw_params(&substream
,
3275 dev_err(source
->dev
,
3276 "ASoC: hw_params() failed: %d\n", ret
);
3281 if (sink
->driver
->ops
&& sink
->driver
->ops
->hw_params
) {
3282 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3283 ret
= sink
->driver
->ops
->hw_params(&substream
, params
,
3287 "ASoC: hw_params() failed: %d\n", ret
);
3293 case SND_SOC_DAPM_POST_PMU
:
3294 ret
= snd_soc_dai_digital_mute(sink
, 0,
3295 SNDRV_PCM_STREAM_PLAYBACK
);
3296 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3297 dev_warn(sink
->dev
, "ASoC: Failed to unmute: %d\n", ret
);
3301 case SND_SOC_DAPM_PRE_PMD
:
3302 ret
= snd_soc_dai_digital_mute(sink
, 1,
3303 SNDRV_PCM_STREAM_PLAYBACK
);
3304 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3305 dev_warn(sink
->dev
, "ASoC: Failed to mute: %d\n", ret
);
3319 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3320 const struct snd_soc_pcm_stream
*params
,
3321 struct snd_soc_dapm_widget
*source
,
3322 struct snd_soc_dapm_widget
*sink
)
3324 struct snd_soc_dapm_route routes
[2];
3325 struct snd_soc_dapm_widget
template;
3326 struct snd_soc_dapm_widget
*w
;
3330 len
= strlen(source
->name
) + strlen(sink
->name
) + 2;
3331 link_name
= devm_kzalloc(card
->dev
, len
, GFP_KERNEL
);
3334 snprintf(link_name
, len
, "%s-%s", source
->name
, sink
->name
);
3336 memset(&template, 0, sizeof(template));
3337 template.reg
= SND_SOC_NOPM
;
3338 template.id
= snd_soc_dapm_dai_link
;
3339 template.name
= link_name
;
3340 template.event
= snd_soc_dai_link_event
;
3341 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3342 SND_SOC_DAPM_PRE_PMD
;
3344 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
3346 w
= snd_soc_dapm_new_control(&card
->dapm
, &template);
3348 dev_err(card
->dev
, "ASoC: Failed to create %s widget\n",
3355 memset(&routes
, 0, sizeof(routes
));
3357 routes
[0].source
= source
->name
;
3358 routes
[0].sink
= link_name
;
3359 routes
[1].source
= link_name
;
3360 routes
[1].sink
= sink
->name
;
3362 return snd_soc_dapm_add_routes(&card
->dapm
, routes
,
3363 ARRAY_SIZE(routes
));
3366 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3367 struct snd_soc_dai
*dai
)
3369 struct snd_soc_dapm_widget
template;
3370 struct snd_soc_dapm_widget
*w
;
3372 WARN_ON(dapm
->dev
!= dai
->dev
);
3374 memset(&template, 0, sizeof(template));
3375 template.reg
= SND_SOC_NOPM
;
3377 if (dai
->driver
->playback
.stream_name
) {
3378 template.id
= snd_soc_dapm_dai
;
3379 template.name
= dai
->driver
->playback
.stream_name
;
3380 template.sname
= dai
->driver
->playback
.stream_name
;
3382 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3385 w
= snd_soc_dapm_new_control(dapm
, &template);
3387 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3388 dai
->driver
->playback
.stream_name
);
3392 dai
->playback_widget
= w
;
3395 if (dai
->driver
->capture
.stream_name
) {
3396 template.id
= snd_soc_dapm_dai
;
3397 template.name
= dai
->driver
->capture
.stream_name
;
3398 template.sname
= dai
->driver
->capture
.stream_name
;
3400 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3403 w
= snd_soc_dapm_new_control(dapm
, &template);
3405 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3406 dai
->driver
->capture
.stream_name
);
3410 dai
->capture_widget
= w
;
3416 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3418 struct snd_soc_dapm_widget
*dai_w
, *w
;
3419 struct snd_soc_dai
*dai
;
3420 struct snd_soc_dapm_route r
;
3422 memset(&r
, 0, sizeof(r
));
3424 /* For each DAI widget... */
3425 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3426 if (dai_w
->id
!= snd_soc_dapm_dai
)
3431 /* ...find all widgets with the same stream and link them */
3432 list_for_each_entry(w
, &card
->widgets
, list
) {
3433 if (w
->dapm
!= dai_w
->dapm
)
3436 if (w
->id
== snd_soc_dapm_dai
)
3442 if (dai
->driver
->playback
.stream_name
&&
3444 dai
->driver
->playback
.stream_name
)) {
3445 r
.source
= dai
->playback_widget
->name
;
3447 dev_dbg(dai
->dev
, "%s -> %s\n",
3450 snd_soc_dapm_add_route(w
->dapm
, &r
);
3453 if (dai
->driver
->capture
.stream_name
&&
3455 dai
->driver
->capture
.stream_name
)) {
3457 r
.sink
= dai
->capture_widget
->name
;
3458 dev_dbg(dai
->dev
, "%s -> %s\n",
3461 snd_soc_dapm_add_route(w
->dapm
, &r
);
3469 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3473 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
3474 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3475 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
3477 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3478 w_cpu
= cpu_dai
->playback_widget
;
3479 w_codec
= codec_dai
->playback_widget
;
3481 w_cpu
= cpu_dai
->capture_widget
;
3482 w_codec
= codec_dai
->capture_widget
;
3487 dapm_mark_dirty(w_cpu
, "stream event");
3490 case SND_SOC_DAPM_STREAM_START
:
3493 case SND_SOC_DAPM_STREAM_STOP
:
3496 case SND_SOC_DAPM_STREAM_SUSPEND
:
3497 case SND_SOC_DAPM_STREAM_RESUME
:
3498 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3499 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3506 dapm_mark_dirty(w_codec
, "stream event");
3509 case SND_SOC_DAPM_STREAM_START
:
3510 w_codec
->active
= 1;
3512 case SND_SOC_DAPM_STREAM_STOP
:
3513 w_codec
->active
= 0;
3515 case SND_SOC_DAPM_STREAM_SUSPEND
:
3516 case SND_SOC_DAPM_STREAM_RESUME
:
3517 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3518 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3523 dapm_power_widgets(&rtd
->card
->dapm
, event
);
3527 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3528 * @rtd: PCM runtime data
3529 * @stream: stream name
3530 * @event: stream event
3532 * Sends a stream event to the dapm core. The core then makes any
3533 * necessary widget power changes.
3535 * Returns 0 for success else error.
3537 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3540 struct snd_soc_card
*card
= rtd
->card
;
3542 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3543 soc_dapm_stream_event(rtd
, stream
, event
);
3544 mutex_unlock(&card
->dapm_mutex
);
3548 * snd_soc_dapm_enable_pin - enable pin.
3549 * @dapm: DAPM context
3552 * Enables input/output pin and its parents or children widgets iff there is
3553 * a valid audio route and active audio stream.
3554 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3555 * do any widget power switching.
3557 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3559 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3561 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3564 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3565 * @dapm: DAPM context
3568 * Enables input/output pin regardless of any other state. This is
3569 * intended for use with microphone bias supplies used in microphone
3572 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3573 * do any widget power switching.
3575 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3578 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3581 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
3585 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
3588 dapm_mark_dirty(w
, "force enable");
3592 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3595 * snd_soc_dapm_disable_pin - disable pin.
3596 * @dapm: DAPM context
3599 * Disables input/output pin and its parents or children widgets.
3600 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3601 * do any widget power switching.
3603 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3606 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3608 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3611 * snd_soc_dapm_nc_pin - permanently disable pin.
3612 * @dapm: DAPM context
3615 * Marks the specified pin as being not connected, disabling it along
3616 * any parent or child widgets. At present this is identical to
3617 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3618 * additional things such as disabling controls which only affect
3619 * paths through the pin.
3621 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3622 * do any widget power switching.
3624 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3626 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3628 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3631 * snd_soc_dapm_get_pin_status - get audio pin status
3632 * @dapm: DAPM context
3633 * @pin: audio signal pin endpoint (or start point)
3635 * Get audio pin status - connected or disconnected.
3637 * Returns 1 for connected otherwise 0.
3639 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3642 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3645 return w
->connected
;
3649 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
3652 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3653 * @dapm: DAPM context
3654 * @pin: audio signal pin endpoint (or start point)
3656 * Mark the given endpoint or pin as ignoring suspend. When the
3657 * system is disabled a path between two endpoints flagged as ignoring
3658 * suspend will not be disabled. The path must already be enabled via
3659 * normal means at suspend time, it will not be turned on if it was not
3662 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
3665 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
3668 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
3672 w
->ignore_suspend
= 1;
3676 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
3678 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
3679 struct snd_soc_dapm_widget
*w
)
3681 struct snd_soc_dapm_path
*p
;
3683 list_for_each_entry(p
, &card
->paths
, list
) {
3684 if ((p
->source
== w
) || (p
->sink
== w
)) {
3686 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3687 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
3688 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
3690 /* Connected to something other than the codec */
3691 if (p
->source
->dapm
!= p
->sink
->dapm
)
3694 * Loopback connection from codec external pin to
3695 * codec external pin
3697 if (p
->sink
->id
== snd_soc_dapm_input
) {
3698 switch (p
->source
->id
) {
3699 case snd_soc_dapm_output
:
3700 case snd_soc_dapm_micbias
:
3713 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3714 * @codec: The codec whose pins should be processed
3716 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3717 * which are unused. Pins are used if they are connected externally to the
3718 * codec, whether that be to some other device, or a loop-back connection to
3721 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
3723 struct snd_soc_card
*card
= codec
->card
;
3724 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3725 struct snd_soc_dapm_widget
*w
;
3727 dev_dbg(codec
->dev
, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n",
3728 &card
->dapm
, &codec
->dapm
);
3730 list_for_each_entry(w
, &card
->widgets
, list
) {
3731 if (w
->dapm
!= dapm
)
3734 case snd_soc_dapm_input
:
3735 case snd_soc_dapm_output
:
3736 case snd_soc_dapm_micbias
:
3737 dev_dbg(codec
->dev
, "ASoC: Auto NC: Checking widget %s\n",
3739 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
3741 "... Not in map; disabling\n");
3742 snd_soc_dapm_nc_pin(dapm
, w
->name
);
3752 * snd_soc_dapm_free - free dapm resources
3753 * @dapm: DAPM context
3755 * Free all dapm widgets and resources.
3757 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
3759 snd_soc_dapm_sys_remove(dapm
->dev
);
3760 dapm_debugfs_cleanup(dapm
);
3761 dapm_free_widgets(dapm
);
3762 list_del(&dapm
->list
);
3764 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
3766 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
3768 struct snd_soc_card
*card
= dapm
->card
;
3769 struct snd_soc_dapm_widget
*w
;
3770 LIST_HEAD(down_list
);
3773 mutex_lock(&card
->dapm_mutex
);
3775 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
3776 if (w
->dapm
!= dapm
)
3779 dapm_seq_insert(w
, &down_list
, false);
3785 /* If there were no widgets to power down we're already in
3789 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
3790 snd_soc_dapm_set_bias_level(dapm
,
3791 SND_SOC_BIAS_PREPARE
);
3792 dapm_seq_run(dapm
, &down_list
, 0, false);
3793 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
3794 snd_soc_dapm_set_bias_level(dapm
,
3795 SND_SOC_BIAS_STANDBY
);
3798 mutex_unlock(&card
->dapm_mutex
);
3802 * snd_soc_dapm_shutdown - callback for system shutdown
3804 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
3806 struct snd_soc_codec
*codec
;
3808 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
3809 soc_dapm_shutdown_codec(&codec
->dapm
);
3810 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
3811 snd_soc_dapm_set_bias_level(&codec
->dapm
,
3816 /* Module information */
3817 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3818 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3819 MODULE_LICENSE("GPL");