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
;
366 if (item
< e
->max
&& !strcmp(p
->name
, e
->texts
[item
]))
372 case snd_soc_dapm_virt_mux
: {
373 struct soc_enum
*e
= (struct soc_enum
*)
374 w
->kcontrol_news
[i
].private_value
;
377 /* since a virtual mux has no backing registers to
378 * decide which path to connect, it will try to match
379 * with the first enumeration. This is to ensure
380 * that the default mux choice (the first) will be
381 * correctly powered up during initialization.
383 if (!strcmp(p
->name
, e
->texts
[0]))
387 case snd_soc_dapm_value_mux
: {
388 struct soc_enum
*e
= (struct soc_enum
*)
389 w
->kcontrol_news
[i
].private_value
;
392 val
= soc_widget_read(w
, e
->reg
);
393 val
= (val
>> e
->shift_l
) & e
->mask
;
394 for (item
= 0; item
< e
->max
; item
++) {
395 if (val
== e
->values
[item
])
399 if (item
< e
->max
&& !strcmp(p
->name
, e
->texts
[item
]))
405 /* does not affect routing - always connected */
406 case snd_soc_dapm_pga
:
407 case snd_soc_dapm_out_drv
:
408 case snd_soc_dapm_output
:
409 case snd_soc_dapm_adc
:
410 case snd_soc_dapm_input
:
411 case snd_soc_dapm_siggen
:
412 case snd_soc_dapm_dac
:
413 case snd_soc_dapm_micbias
:
414 case snd_soc_dapm_vmid
:
415 case snd_soc_dapm_supply
:
416 case snd_soc_dapm_regulator_supply
:
417 case snd_soc_dapm_clock_supply
:
418 case snd_soc_dapm_aif_in
:
419 case snd_soc_dapm_aif_out
:
420 case snd_soc_dapm_dai
:
421 case snd_soc_dapm_hp
:
422 case snd_soc_dapm_mic
:
423 case snd_soc_dapm_spk
:
424 case snd_soc_dapm_line
:
425 case snd_soc_dapm_dai_link
:
428 /* does affect routing - dynamically connected */
429 case snd_soc_dapm_pre
:
430 case snd_soc_dapm_post
:
436 /* connect mux widget to its interconnecting audio paths */
437 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
438 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
439 struct snd_soc_dapm_path
*path
, const char *control_name
,
440 const struct snd_kcontrol_new
*kcontrol
)
442 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
445 for (i
= 0; i
< e
->max
; i
++) {
446 if (!(strcmp(control_name
, e
->texts
[i
]))) {
447 list_add(&path
->list
, &dapm
->card
->paths
);
448 list_add(&path
->list_sink
, &dest
->sources
);
449 list_add(&path
->list_source
, &src
->sinks
);
450 path
->name
= (char*)e
->texts
[i
];
451 dapm_set_path_status(dest
, path
, 0);
459 /* connect mixer widget to its interconnecting audio paths */
460 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
461 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
462 struct snd_soc_dapm_path
*path
, const char *control_name
)
466 /* search for mixer kcontrol */
467 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
468 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
469 list_add(&path
->list
, &dapm
->card
->paths
);
470 list_add(&path
->list_sink
, &dest
->sources
);
471 list_add(&path
->list_source
, &src
->sinks
);
472 path
->name
= dest
->kcontrol_news
[i
].name
;
473 dapm_set_path_status(dest
, path
, i
);
480 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
481 struct snd_soc_dapm_widget
*kcontrolw
,
482 const struct snd_kcontrol_new
*kcontrol_new
,
483 struct snd_kcontrol
**kcontrol
)
485 struct snd_soc_dapm_widget
*w
;
490 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
491 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
493 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
494 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
496 *kcontrol
= w
->kcontrols
[i
];
505 static void dapm_kcontrol_free(struct snd_kcontrol
*kctl
)
507 kfree(kctl
->private_data
);
511 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
512 * create it. Either way, add the widget into the control's widget list
514 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget
*w
,
515 int kci
, struct snd_soc_dapm_path
*path
)
517 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
518 struct snd_card
*card
= dapm
->card
->snd_card
;
522 struct snd_kcontrol
*kcontrol
;
523 struct snd_soc_dapm_widget_list
*wlist
;
526 bool wname_in_long_name
, kcname_in_long_name
;
533 prefix
= dapm
->codec
->name_prefix
;
538 prefix_len
= strlen(prefix
) + 1;
542 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
546 wlist
= kcontrol
->private_data
;
547 wlistentries
= wlist
->num_widgets
+ 1;
553 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
554 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
555 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
557 dev_err(dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
561 wlist
->num_widgets
= wlistentries
;
562 wlist
->widgets
[wlistentries
- 1] = w
;
566 wname_in_long_name
= false;
567 kcname_in_long_name
= true;
570 case snd_soc_dapm_switch
:
571 case snd_soc_dapm_mixer
:
572 wname_in_long_name
= true;
573 kcname_in_long_name
= true;
575 case snd_soc_dapm_mixer_named_ctl
:
576 wname_in_long_name
= false;
577 kcname_in_long_name
= true;
579 case snd_soc_dapm_mux
:
580 case snd_soc_dapm_virt_mux
:
581 case snd_soc_dapm_value_mux
:
582 wname_in_long_name
= true;
583 kcname_in_long_name
= false;
591 if (wname_in_long_name
&& kcname_in_long_name
) {
592 name_len
= strlen(w
->name
) - prefix_len
+ 1 +
593 strlen(w
->kcontrol_news
[kci
].name
) + 1;
595 long_name
= kmalloc(name_len
, GFP_KERNEL
);
596 if (long_name
== NULL
) {
602 * The control will get a prefix from the control
603 * creation process but we're also using the same
604 * prefix for widgets so cut the prefix off the
605 * front of the widget name.
607 snprintf(long_name
, name_len
, "%s %s",
608 w
->name
+ prefix_len
,
609 w
->kcontrol_news
[kci
].name
);
610 long_name
[name_len
- 1] = '\0';
613 } else if (wname_in_long_name
) {
615 name
= w
->name
+ prefix_len
;
618 name
= w
->kcontrol_news
[kci
].name
;
621 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], wlist
, name
,
623 kcontrol
->private_free
= dapm_kcontrol_free
;
624 ret
= snd_ctl_add(card
, kcontrol
);
627 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
634 path
->long_name
= long_name
;
637 kcontrol
->private_data
= wlist
;
638 w
->kcontrols
[kci
] = kcontrol
;
639 path
->kcontrol
= kcontrol
;
644 /* create new dapm mixer control */
645 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
648 struct snd_soc_dapm_path
*path
;
651 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
653 list_for_each_entry(path
, &w
->sources
, list_sink
) {
654 /* mixer/mux paths name must match control name */
655 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
658 if (w
->kcontrols
[i
]) {
659 path
->kcontrol
= w
->kcontrols
[i
];
663 ret
= dapm_create_or_share_mixmux_kcontrol(w
, i
, path
);
672 /* create new dapm mux control */
673 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
675 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
676 struct snd_soc_dapm_path
*path
;
679 if (w
->num_kcontrols
!= 1) {
681 "ASoC: mux %s has incorrect number of controls\n",
686 path
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
689 dev_err(dapm
->dev
, "ASoC: mux %s has no paths\n", w
->name
);
693 ret
= dapm_create_or_share_mixmux_kcontrol(w
, 0, path
);
697 list_for_each_entry(path
, &w
->sources
, list_sink
)
698 path
->kcontrol
= w
->kcontrols
[0];
703 /* create new dapm volume control */
704 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
706 if (w
->num_kcontrols
)
707 dev_err(w
->dapm
->dev
,
708 "ASoC: PGA controls not supported: '%s'\n", w
->name
);
713 /* reset 'walked' bit for each dapm path */
714 static void dapm_clear_walk_output(struct snd_soc_dapm_context
*dapm
,
715 struct list_head
*sink
)
717 struct snd_soc_dapm_path
*p
;
719 list_for_each_entry(p
, sink
, list_source
) {
722 dapm_clear_walk_output(dapm
, &p
->sink
->sinks
);
727 static void dapm_clear_walk_input(struct snd_soc_dapm_context
*dapm
,
728 struct list_head
*source
)
730 struct snd_soc_dapm_path
*p
;
732 list_for_each_entry(p
, source
, list_sink
) {
735 dapm_clear_walk_input(dapm
, &p
->source
->sources
);
741 /* We implement power down on suspend by checking the power state of
742 * the ALSA card - when we are suspending the ALSA state for the card
745 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
747 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
750 case SNDRV_CTL_POWER_D3hot
:
751 case SNDRV_CTL_POWER_D3cold
:
752 if (widget
->ignore_suspend
)
753 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
755 return widget
->ignore_suspend
;
761 /* add widget to list if it's not already in the list */
762 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
763 struct snd_soc_dapm_widget
*w
)
765 struct snd_soc_dapm_widget_list
*wlist
;
766 int wlistsize
, wlistentries
, i
;
773 /* is this widget already in the list */
774 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
775 if (wlist
->widgets
[i
] == w
)
779 /* allocate some new space */
780 wlistentries
= wlist
->num_widgets
+ 1;
781 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
782 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
783 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
785 dev_err(w
->dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
791 /* insert the widget */
792 dev_dbg(w
->dapm
->dev
, "ASoC: added %s in widget list pos %d\n",
793 w
->name
, wlist
->num_widgets
);
795 wlist
->widgets
[wlist
->num_widgets
] = w
;
796 wlist
->num_widgets
++;
801 * Recursively check for a completed path to an active or physically connected
802 * output widget. Returns number of complete paths.
804 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
805 struct snd_soc_dapm_widget_list
**list
)
807 struct snd_soc_dapm_path
*path
;
810 if (widget
->outputs
>= 0)
811 return widget
->outputs
;
813 DAPM_UPDATE_STAT(widget
, path_checks
);
815 switch (widget
->id
) {
816 case snd_soc_dapm_supply
:
817 case snd_soc_dapm_regulator_supply
:
818 case snd_soc_dapm_clock_supply
:
824 switch (widget
->id
) {
825 case snd_soc_dapm_adc
:
826 case snd_soc_dapm_aif_out
:
827 case snd_soc_dapm_dai
:
828 if (widget
->active
) {
829 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
830 return widget
->outputs
;
836 if (widget
->connected
) {
837 /* connected pin ? */
838 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
839 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
840 return widget
->outputs
;
843 /* connected jack or spk ? */
844 if (widget
->id
== snd_soc_dapm_hp
||
845 widget
->id
== snd_soc_dapm_spk
||
846 (widget
->id
== snd_soc_dapm_line
&&
847 !list_empty(&widget
->sources
))) {
848 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
849 return widget
->outputs
;
853 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
854 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
865 trace_snd_soc_dapm_output_path(widget
, path
);
867 if (path
->sink
&& path
->connect
) {
871 /* do we need to add this widget to the list ? */
874 err
= dapm_list_add_widget(list
, path
->sink
);
876 dev_err(widget
->dapm
->dev
,
877 "ASoC: could not add widget %s\n",
884 con
+= is_connected_output_ep(path
->sink
, list
);
890 widget
->outputs
= con
;
896 * Recursively check for a completed path to an active or physically connected
897 * input widget. Returns number of complete paths.
899 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
900 struct snd_soc_dapm_widget_list
**list
)
902 struct snd_soc_dapm_path
*path
;
905 if (widget
->inputs
>= 0)
906 return widget
->inputs
;
908 DAPM_UPDATE_STAT(widget
, path_checks
);
910 switch (widget
->id
) {
911 case snd_soc_dapm_supply
:
912 case snd_soc_dapm_regulator_supply
:
913 case snd_soc_dapm_clock_supply
:
919 /* active stream ? */
920 switch (widget
->id
) {
921 case snd_soc_dapm_dac
:
922 case snd_soc_dapm_aif_in
:
923 case snd_soc_dapm_dai
:
924 if (widget
->active
) {
925 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
926 return widget
->inputs
;
932 if (widget
->connected
) {
933 /* connected pin ? */
934 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
935 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
936 return widget
->inputs
;
939 /* connected VMID/Bias for lower pops */
940 if (widget
->id
== snd_soc_dapm_vmid
) {
941 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
942 return widget
->inputs
;
945 /* connected jack ? */
946 if (widget
->id
== snd_soc_dapm_mic
||
947 (widget
->id
== snd_soc_dapm_line
&&
948 !list_empty(&widget
->sinks
))) {
949 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
950 return widget
->inputs
;
953 /* signal generator */
954 if (widget
->id
== snd_soc_dapm_siggen
) {
955 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
956 return widget
->inputs
;
960 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
961 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
972 trace_snd_soc_dapm_input_path(widget
, path
);
974 if (path
->source
&& path
->connect
) {
978 /* do we need to add this widget to the list ? */
981 err
= dapm_list_add_widget(list
, path
->source
);
983 dev_err(widget
->dapm
->dev
,
984 "ASoC: could not add widget %s\n",
991 con
+= is_connected_input_ep(path
->source
, list
);
997 widget
->inputs
= con
;
1003 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1004 * @dai: the soc DAI.
1005 * @stream: stream direction.
1006 * @list: list of active widgets for this stream.
1008 * Queries DAPM graph as to whether an valid audio stream path exists for
1009 * the initial stream specified by name. This takes into account
1010 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1012 * Returns the number of valid paths or negative error.
1014 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1015 struct snd_soc_dapm_widget_list
**list
)
1017 struct snd_soc_card
*card
= dai
->card
;
1020 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1023 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1024 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
1025 dapm_clear_walk_output(&card
->dapm
,
1026 &dai
->playback_widget
->sinks
);
1028 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
1029 dapm_clear_walk_input(&card
->dapm
,
1030 &dai
->capture_widget
->sources
);
1033 trace_snd_soc_dapm_connected(paths
, stream
);
1034 mutex_unlock(&card
->dapm_mutex
);
1040 * Handler for generic register modifier widget.
1042 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
1043 struct snd_kcontrol
*kcontrol
, int event
)
1047 if (SND_SOC_DAPM_EVENT_ON(event
))
1052 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
1053 w
->mask
<< w
->shift
, val
<< w
->shift
);
1057 EXPORT_SYMBOL_GPL(dapm_reg_event
);
1060 * Handler for regulator supply widget.
1062 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1063 struct snd_kcontrol
*kcontrol
, int event
)
1067 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1068 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1069 ret
= regulator_allow_bypass(w
->regulator
, false);
1071 dev_warn(w
->dapm
->dev
,
1072 "ASoC: Failed to bypass %s: %d\n",
1076 return regulator_enable(w
->regulator
);
1078 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1079 ret
= regulator_allow_bypass(w
->regulator
, true);
1081 dev_warn(w
->dapm
->dev
,
1082 "ASoC: Failed to unbypass %s: %d\n",
1086 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1089 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1092 * Handler for clock supply widget.
1094 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1095 struct snd_kcontrol
*kcontrol
, int event
)
1100 #ifdef CONFIG_HAVE_CLK
1101 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1102 return clk_prepare_enable(w
->clk
);
1104 clk_disable_unprepare(w
->clk
);
1110 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1112 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1114 if (w
->power_checked
)
1115 return w
->new_power
;
1120 w
->new_power
= w
->power_check(w
);
1122 w
->power_checked
= true;
1124 return w
->new_power
;
1127 /* Generic check to see if a widget should be powered.
1129 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1133 DAPM_UPDATE_STAT(w
, power_checks
);
1135 in
= is_connected_input_ep(w
, NULL
);
1136 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1137 out
= is_connected_output_ep(w
, NULL
);
1138 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1139 return out
!= 0 && in
!= 0;
1142 static int dapm_dai_check_power(struct snd_soc_dapm_widget
*w
)
1144 DAPM_UPDATE_STAT(w
, power_checks
);
1149 return dapm_generic_check_power(w
);
1152 /* Check to see if an ADC has power */
1153 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
1157 DAPM_UPDATE_STAT(w
, power_checks
);
1160 in
= is_connected_input_ep(w
, NULL
);
1161 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1164 return dapm_generic_check_power(w
);
1168 /* Check to see if a DAC has power */
1169 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
1173 DAPM_UPDATE_STAT(w
, power_checks
);
1176 out
= is_connected_output_ep(w
, NULL
);
1177 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1180 return dapm_generic_check_power(w
);
1184 /* Check to see if a power supply is needed */
1185 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1187 struct snd_soc_dapm_path
*path
;
1189 DAPM_UPDATE_STAT(w
, power_checks
);
1191 /* Check if one of our outputs is connected */
1192 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1193 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1198 if (path
->connected
&&
1199 !path
->connected(path
->source
, path
->sink
))
1205 if (dapm_widget_power_check(path
->sink
))
1212 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1217 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1218 struct snd_soc_dapm_widget
*b
,
1226 sort
= dapm_down_seq
;
1228 if (sort
[a
->id
] != sort
[b
->id
])
1229 return sort
[a
->id
] - sort
[b
->id
];
1230 if (a
->subseq
!= b
->subseq
) {
1232 return a
->subseq
- b
->subseq
;
1234 return b
->subseq
- a
->subseq
;
1236 if (a
->reg
!= b
->reg
)
1237 return a
->reg
- b
->reg
;
1238 if (a
->dapm
!= b
->dapm
)
1239 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1244 /* Insert a widget in order into a DAPM power sequence. */
1245 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1246 struct list_head
*list
,
1249 struct snd_soc_dapm_widget
*w
;
1251 list_for_each_entry(w
, list
, power_list
)
1252 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1253 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1257 list_add_tail(&new_widget
->power_list
, list
);
1260 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
1261 struct snd_soc_dapm_widget
*w
, int event
)
1263 struct snd_soc_card
*card
= dapm
->card
;
1264 const char *ev_name
;
1268 case SND_SOC_DAPM_PRE_PMU
:
1269 ev_name
= "PRE_PMU";
1272 case SND_SOC_DAPM_POST_PMU
:
1273 ev_name
= "POST_PMU";
1276 case SND_SOC_DAPM_PRE_PMD
:
1277 ev_name
= "PRE_PMD";
1280 case SND_SOC_DAPM_POST_PMD
:
1281 ev_name
= "POST_PMD";
1289 if (w
->power
!= power
)
1292 if (w
->event
&& (w
->event_flags
& event
)) {
1293 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1295 trace_snd_soc_dapm_widget_event_start(w
, event
);
1296 ret
= w
->event(w
, NULL
, event
);
1297 trace_snd_soc_dapm_widget_event_done(w
, event
);
1299 dev_err(dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1300 ev_name
, w
->name
, ret
);
1304 /* Apply the coalesced changes from a DAPM sequence */
1305 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
1306 struct list_head
*pending
)
1308 struct snd_soc_card
*card
= dapm
->card
;
1309 struct snd_soc_dapm_widget
*w
;
1311 unsigned int value
= 0;
1312 unsigned int mask
= 0;
1313 unsigned int cur_mask
;
1315 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1318 list_for_each_entry(w
, pending
, power_list
) {
1319 cur_mask
= 1 << w
->shift
;
1320 BUG_ON(reg
!= w
->reg
);
1331 pop_dbg(dapm
->dev
, card
->pop_time
,
1332 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1333 w
->name
, reg
, value
, mask
);
1335 /* Check for events */
1336 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
1337 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
1341 /* Any widget will do, they should all be updating the
1344 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1347 pop_dbg(dapm
->dev
, card
->pop_time
,
1348 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1349 value
, mask
, reg
, card
->pop_time
);
1350 pop_wait(card
->pop_time
);
1351 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1354 list_for_each_entry(w
, pending
, power_list
) {
1355 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
1356 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
1360 /* Apply a DAPM power sequence.
1362 * We walk over a pre-sorted list of widgets to apply power to. In
1363 * order to minimise the number of writes to the device required
1364 * multiple widgets will be updated in a single write where possible.
1365 * Currently anything that requires more than a single write is not
1368 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
1369 struct list_head
*list
, int event
, bool power_up
)
1371 struct snd_soc_dapm_widget
*w
, *n
;
1374 int cur_subseq
= -1;
1375 int cur_reg
= SND_SOC_NOPM
;
1376 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1383 sort
= dapm_down_seq
;
1385 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1388 /* Do we need to apply any queued changes? */
1389 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1390 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1391 if (!list_empty(&pending
))
1392 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1394 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1395 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1396 if (sort
[i
] == cur_sort
)
1397 cur_dapm
->seq_notifier(cur_dapm
,
1402 INIT_LIST_HEAD(&pending
);
1404 cur_subseq
= INT_MIN
;
1405 cur_reg
= SND_SOC_NOPM
;
1410 case snd_soc_dapm_pre
:
1412 list_for_each_entry_safe_continue(w
, n
, list
,
1415 if (event
== SND_SOC_DAPM_STREAM_START
)
1417 NULL
, SND_SOC_DAPM_PRE_PMU
);
1418 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1420 NULL
, SND_SOC_DAPM_PRE_PMD
);
1423 case snd_soc_dapm_post
:
1425 list_for_each_entry_safe_continue(w
, n
, list
,
1428 if (event
== SND_SOC_DAPM_STREAM_START
)
1430 NULL
, SND_SOC_DAPM_POST_PMU
);
1431 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1433 NULL
, SND_SOC_DAPM_POST_PMD
);
1437 /* Queue it up for application */
1438 cur_sort
= sort
[w
->id
];
1439 cur_subseq
= w
->subseq
;
1442 list_move(&w
->power_list
, &pending
);
1447 dev_err(w
->dapm
->dev
,
1448 "ASoC: Failed to apply widget power: %d\n", ret
);
1451 if (!list_empty(&pending
))
1452 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1454 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1455 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1456 if (sort
[i
] == cur_sort
)
1457 cur_dapm
->seq_notifier(cur_dapm
,
1462 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1464 struct snd_soc_dapm_update
*update
= dapm
->update
;
1465 struct snd_soc_dapm_widget
*w
;
1474 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1475 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1477 dev_err(dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1481 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1484 dev_err(dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1488 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1489 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1491 dev_err(dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1496 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1497 * they're changing state.
1499 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1501 struct snd_soc_dapm_context
*d
= data
;
1504 /* If we're off and we're not supposed to be go into STANDBY */
1505 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1506 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1508 pm_runtime_get_sync(d
->dev
);
1510 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1513 "ASoC: Failed to turn on bias: %d\n", ret
);
1516 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1517 if (d
->bias_level
!= d
->target_bias_level
) {
1518 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1521 "ASoC: Failed to prepare bias: %d\n", ret
);
1525 /* Async callback run prior to DAPM sequences - brings to their final
1528 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1530 struct snd_soc_dapm_context
*d
= data
;
1533 /* If we just powered the last thing off drop to standby bias */
1534 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1535 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1536 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1537 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1539 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1543 /* If we're in standby and can support bias off then do that */
1544 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1545 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1546 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1548 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1552 pm_runtime_put(d
->dev
);
1555 /* If we just powered up then move to active bias */
1556 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1557 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1558 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1560 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1565 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1566 bool power
, bool connect
)
1568 /* If a connection is being made or broken then that update
1569 * will have marked the peer dirty, otherwise the widgets are
1570 * not connected and this update has no impact. */
1574 /* If the peer is already in the state we're moving to then we
1575 * won't have an impact on it. */
1576 if (power
!= peer
->power
)
1577 dapm_mark_dirty(peer
, "peer state change");
1580 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1581 struct list_head
*up_list
,
1582 struct list_head
*down_list
)
1584 struct snd_soc_dapm_path
*path
;
1586 if (w
->power
== power
)
1589 trace_snd_soc_dapm_widget_power(w
, power
);
1591 /* If we changed our power state perhaps our neigbours changed
1594 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1596 dapm_widget_set_peer_power(path
->source
, power
,
1601 case snd_soc_dapm_supply
:
1602 case snd_soc_dapm_regulator_supply
:
1603 case snd_soc_dapm_clock_supply
:
1604 /* Supplies can't affect their outputs, only their inputs */
1607 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1609 dapm_widget_set_peer_power(path
->sink
, power
,
1617 dapm_seq_insert(w
, up_list
, true);
1619 dapm_seq_insert(w
, down_list
, false);
1624 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1625 struct list_head
*up_list
,
1626 struct list_head
*down_list
)
1631 case snd_soc_dapm_pre
:
1632 dapm_seq_insert(w
, down_list
, false);
1634 case snd_soc_dapm_post
:
1635 dapm_seq_insert(w
, up_list
, true);
1639 power
= dapm_widget_power_check(w
);
1641 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1647 * Scan each dapm widget for complete audio path.
1648 * A complete path is a route that has valid endpoints i.e.:-
1650 * o DAC to output pin.
1651 * o Input Pin to ADC.
1652 * o Input pin to Output pin (bypass, sidetone)
1653 * o DAC to ADC (loopback).
1655 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1657 struct snd_soc_card
*card
= dapm
->card
;
1658 struct snd_soc_dapm_widget
*w
;
1659 struct snd_soc_dapm_context
*d
;
1661 LIST_HEAD(down_list
);
1662 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1663 enum snd_soc_bias_level bias
;
1665 trace_snd_soc_dapm_start(card
);
1667 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1668 if (d
->idle_bias_off
)
1669 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1671 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1676 /* Check which widgets we need to power and store them in
1677 * lists indicating if they should be powered up or down. We
1678 * only check widgets that have been flagged as dirty but note
1679 * that new widgets may be added to the dirty list while we
1682 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1683 dapm_power_one_widget(w
, &up_list
, &down_list
);
1686 list_for_each_entry(w
, &card
->widgets
, list
) {
1688 case snd_soc_dapm_pre
:
1689 case snd_soc_dapm_post
:
1690 /* These widgets always need to be powered */
1693 list_del_init(&w
->dirty
);
1700 /* Supplies and micbiases only bring the
1701 * context up to STANDBY as unless something
1702 * else is active and passing audio they
1703 * generally don't require full power. Signal
1704 * generators are virtual pins and have no
1705 * power impact themselves.
1708 case snd_soc_dapm_siggen
:
1710 case snd_soc_dapm_supply
:
1711 case snd_soc_dapm_regulator_supply
:
1712 case snd_soc_dapm_clock_supply
:
1713 case snd_soc_dapm_micbias
:
1714 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1715 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1718 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1725 /* Force all contexts in the card to the same bias state if
1726 * they're not ground referenced.
1728 bias
= SND_SOC_BIAS_OFF
;
1729 list_for_each_entry(d
, &card
->dapm_list
, list
)
1730 if (d
->target_bias_level
> bias
)
1731 bias
= d
->target_bias_level
;
1732 list_for_each_entry(d
, &card
->dapm_list
, list
)
1733 if (!d
->idle_bias_off
)
1734 d
->target_bias_level
= bias
;
1736 trace_snd_soc_dapm_walk_done(card
);
1738 /* Run all the bias changes in parallel */
1739 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1740 async_schedule_domain(dapm_pre_sequence_async
, d
,
1742 async_synchronize_full_domain(&async_domain
);
1744 /* Power down widgets first; try to avoid amplifying pops. */
1745 dapm_seq_run(dapm
, &down_list
, event
, false);
1747 dapm_widget_update(dapm
);
1750 dapm_seq_run(dapm
, &up_list
, event
, true);
1752 /* Run all the bias changes in parallel */
1753 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1754 async_schedule_domain(dapm_post_sequence_async
, d
,
1756 async_synchronize_full_domain(&async_domain
);
1758 /* do we need to notify any clients that DAPM event is complete */
1759 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1760 if (d
->stream_event
)
1761 d
->stream_event(d
, event
);
1764 pop_dbg(dapm
->dev
, card
->pop_time
,
1765 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1766 pop_wait(card
->pop_time
);
1768 trace_snd_soc_dapm_done(card
);
1773 #ifdef CONFIG_DEBUG_FS
1774 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1775 char __user
*user_buf
,
1776 size_t count
, loff_t
*ppos
)
1778 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1782 struct snd_soc_dapm_path
*p
= NULL
;
1784 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1788 in
= is_connected_input_ep(w
, NULL
);
1789 dapm_clear_walk_input(w
->dapm
, &w
->sources
);
1790 out
= is_connected_output_ep(w
, NULL
);
1791 dapm_clear_walk_output(w
->dapm
, &w
->sinks
);
1793 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1794 w
->name
, w
->power
? "On" : "Off",
1795 w
->force
? " (forced)" : "", in
, out
);
1798 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1799 " - R%d(0x%x) bit %d",
1800 w
->reg
, w
->reg
, w
->shift
);
1802 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1805 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1807 w
->active
? "active" : "inactive");
1809 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1810 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1814 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1815 " in \"%s\" \"%s\"\n",
1816 p
->name
? p
->name
: "static",
1819 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1820 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1824 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1825 " out \"%s\" \"%s\"\n",
1826 p
->name
? p
->name
: "static",
1830 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1836 static const struct file_operations dapm_widget_power_fops
= {
1837 .open
= simple_open
,
1838 .read
= dapm_widget_power_read_file
,
1839 .llseek
= default_llseek
,
1842 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1843 size_t count
, loff_t
*ppos
)
1845 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1848 switch (dapm
->bias_level
) {
1849 case SND_SOC_BIAS_ON
:
1852 case SND_SOC_BIAS_PREPARE
:
1853 level
= "Prepare\n";
1855 case SND_SOC_BIAS_STANDBY
:
1856 level
= "Standby\n";
1858 case SND_SOC_BIAS_OFF
:
1863 level
= "Unknown\n";
1867 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1871 static const struct file_operations dapm_bias_fops
= {
1872 .open
= simple_open
,
1873 .read
= dapm_bias_read_file
,
1874 .llseek
= default_llseek
,
1877 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1878 struct dentry
*parent
)
1882 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1884 if (!dapm
->debugfs_dapm
) {
1886 "ASoC: Failed to create DAPM debugfs directory\n");
1890 d
= debugfs_create_file("bias_level", 0444,
1891 dapm
->debugfs_dapm
, dapm
,
1895 "ASoC: Failed to create bias level debugfs file\n");
1898 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1900 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1903 if (!dapm
->debugfs_dapm
|| !w
->name
)
1906 d
= debugfs_create_file(w
->name
, 0444,
1907 dapm
->debugfs_dapm
, w
,
1908 &dapm_widget_power_fops
);
1910 dev_warn(w
->dapm
->dev
,
1911 "ASoC: Failed to create %s debugfs file\n",
1915 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1917 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1921 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1922 struct dentry
*parent
)
1926 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1930 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1936 /* test and update the power status of a mux widget */
1937 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1938 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1940 struct snd_soc_dapm_path
*path
;
1943 if (widget
->id
!= snd_soc_dapm_mux
&&
1944 widget
->id
!= snd_soc_dapm_virt_mux
&&
1945 widget
->id
!= snd_soc_dapm_value_mux
)
1948 /* find dapm widget path assoc with kcontrol */
1949 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1950 if (path
->kcontrol
!= kcontrol
)
1953 if (!path
->name
|| !e
->texts
[mux
])
1957 /* we now need to match the string in the enum to the path */
1958 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
1959 path
->connect
= 1; /* new connection */
1960 dapm_mark_dirty(path
->source
, "mux connection");
1963 dapm_mark_dirty(path
->source
,
1964 "mux disconnection");
1965 path
->connect
= 0; /* old connection must be powered down */
1970 dapm_mark_dirty(widget
, "mux change");
1971 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1977 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1978 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1980 struct snd_soc_card
*card
= widget
->dapm
->card
;
1983 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1984 ret
= soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
1985 mutex_unlock(&card
->dapm_mutex
);
1987 soc_dpcm_runtime_update(widget
);
1990 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
1992 /* test and update the power status of a mixer or switch widget */
1993 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1994 struct snd_kcontrol
*kcontrol
, int connect
)
1996 struct snd_soc_dapm_path
*path
;
1999 if (widget
->id
!= snd_soc_dapm_mixer
&&
2000 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
2001 widget
->id
!= snd_soc_dapm_switch
)
2004 /* find dapm widget path assoc with kcontrol */
2005 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
2006 if (path
->kcontrol
!= kcontrol
)
2009 /* found, now check type */
2011 path
->connect
= connect
;
2012 dapm_mark_dirty(path
->source
, "mixer connection");
2016 dapm_mark_dirty(widget
, "mixer update");
2017 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
2023 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
2024 struct snd_kcontrol
*kcontrol
, int connect
)
2026 struct snd_soc_card
*card
= widget
->dapm
->card
;
2029 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2030 ret
= soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2031 mutex_unlock(&card
->dapm_mutex
);
2033 soc_dpcm_runtime_update(widget
);
2036 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2038 /* show dapm widget status in sys fs */
2039 static ssize_t
dapm_widget_show(struct device
*dev
,
2040 struct device_attribute
*attr
, char *buf
)
2042 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2043 struct snd_soc_codec
*codec
=rtd
->codec
;
2044 struct snd_soc_dapm_widget
*w
;
2046 char *state
= "not set";
2048 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
2049 if (w
->dapm
!= &codec
->dapm
)
2052 /* only display widgets that burnm power */
2054 case snd_soc_dapm_hp
:
2055 case snd_soc_dapm_mic
:
2056 case snd_soc_dapm_spk
:
2057 case snd_soc_dapm_line
:
2058 case snd_soc_dapm_micbias
:
2059 case snd_soc_dapm_dac
:
2060 case snd_soc_dapm_adc
:
2061 case snd_soc_dapm_pga
:
2062 case snd_soc_dapm_out_drv
:
2063 case snd_soc_dapm_mixer
:
2064 case snd_soc_dapm_mixer_named_ctl
:
2065 case snd_soc_dapm_supply
:
2066 case snd_soc_dapm_regulator_supply
:
2067 case snd_soc_dapm_clock_supply
:
2069 count
+= sprintf(buf
+ count
, "%s: %s\n",
2070 w
->name
, w
->power
? "On":"Off");
2077 switch (codec
->dapm
.bias_level
) {
2078 case SND_SOC_BIAS_ON
:
2081 case SND_SOC_BIAS_PREPARE
:
2084 case SND_SOC_BIAS_STANDBY
:
2087 case SND_SOC_BIAS_OFF
:
2091 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2096 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2098 int snd_soc_dapm_sys_add(struct device
*dev
)
2100 return device_create_file(dev
, &dev_attr_dapm_widget
);
2103 static void snd_soc_dapm_sys_remove(struct device
*dev
)
2105 device_remove_file(dev
, &dev_attr_dapm_widget
);
2108 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2110 list_del(&path
->list_sink
);
2111 list_del(&path
->list_source
);
2112 list_del(&path
->list
);
2113 kfree(path
->long_name
);
2117 /* free all dapm widgets and resources */
2118 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2120 struct snd_soc_dapm_widget
*w
, *next_w
;
2121 struct snd_soc_dapm_path
*p
, *next_p
;
2123 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2124 if (w
->dapm
!= dapm
)
2128 * remove source and sink paths associated to this widget.
2129 * While removing the path, remove reference to it from both
2130 * source and sink widgets so that path is removed only once.
2132 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
)
2135 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
)
2138 kfree(w
->kcontrols
);
2144 static struct snd_soc_dapm_widget
*dapm_find_widget(
2145 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2146 bool search_other_contexts
)
2148 struct snd_soc_dapm_widget
*w
;
2149 struct snd_soc_dapm_widget
*fallback
= NULL
;
2151 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2152 if (!strcmp(w
->name
, pin
)) {
2153 if (w
->dapm
== dapm
)
2160 if (search_other_contexts
)
2166 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2167 const char *pin
, int status
)
2169 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2172 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2176 if (w
->connected
!= status
)
2177 dapm_mark_dirty(w
, "pin configuration");
2179 w
->connected
= status
;
2187 * snd_soc_dapm_sync - scan and power dapm paths
2188 * @dapm: DAPM context
2190 * Walks all dapm audio paths and powers widgets according to their
2191 * stream or path usage.
2193 * Returns 0 for success.
2195 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2200 * Suppress early reports (eg, jacks syncing their state) to avoid
2201 * silly DAPM runs during card startup.
2203 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2206 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2207 ret
= dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2208 mutex_unlock(&dapm
->card
->dapm_mutex
);
2211 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2213 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2214 const struct snd_soc_dapm_route
*route
)
2216 struct snd_soc_dapm_path
*path
;
2217 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2218 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2220 const char *control
= route
->control
;
2222 char prefixed_sink
[80];
2223 char prefixed_source
[80];
2226 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2227 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2228 dapm
->codec
->name_prefix
, route
->sink
);
2229 sink
= prefixed_sink
;
2230 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2231 dapm
->codec
->name_prefix
, route
->source
);
2232 source
= prefixed_source
;
2235 source
= route
->source
;
2239 * find src and dest widgets over all widgets but favor a widget from
2240 * current DAPM context
2242 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2243 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2245 if (w
->dapm
== dapm
)
2249 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2251 if (w
->dapm
== dapm
)
2255 /* use widget from another DAPM context if not found from this */
2261 if (wsource
== NULL
) {
2262 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2266 if (wsink
== NULL
) {
2267 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2272 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2276 path
->source
= wsource
;
2278 path
->connected
= route
->connected
;
2279 INIT_LIST_HEAD(&path
->list
);
2280 INIT_LIST_HEAD(&path
->list_source
);
2281 INIT_LIST_HEAD(&path
->list_sink
);
2283 /* check for external widgets */
2284 if (wsink
->id
== snd_soc_dapm_input
) {
2285 if (wsource
->id
== snd_soc_dapm_micbias
||
2286 wsource
->id
== snd_soc_dapm_mic
||
2287 wsource
->id
== snd_soc_dapm_line
||
2288 wsource
->id
== snd_soc_dapm_output
)
2291 if (wsource
->id
== snd_soc_dapm_output
) {
2292 if (wsink
->id
== snd_soc_dapm_spk
||
2293 wsink
->id
== snd_soc_dapm_hp
||
2294 wsink
->id
== snd_soc_dapm_line
||
2295 wsink
->id
== snd_soc_dapm_input
)
2299 /* connect static paths */
2300 if (control
== NULL
) {
2301 list_add(&path
->list
, &dapm
->card
->paths
);
2302 list_add(&path
->list_sink
, &wsink
->sources
);
2303 list_add(&path
->list_source
, &wsource
->sinks
);
2308 /* connect dynamic paths */
2309 switch (wsink
->id
) {
2310 case snd_soc_dapm_adc
:
2311 case snd_soc_dapm_dac
:
2312 case snd_soc_dapm_pga
:
2313 case snd_soc_dapm_out_drv
:
2314 case snd_soc_dapm_input
:
2315 case snd_soc_dapm_output
:
2316 case snd_soc_dapm_siggen
:
2317 case snd_soc_dapm_micbias
:
2318 case snd_soc_dapm_vmid
:
2319 case snd_soc_dapm_pre
:
2320 case snd_soc_dapm_post
:
2321 case snd_soc_dapm_supply
:
2322 case snd_soc_dapm_regulator_supply
:
2323 case snd_soc_dapm_clock_supply
:
2324 case snd_soc_dapm_aif_in
:
2325 case snd_soc_dapm_aif_out
:
2326 case snd_soc_dapm_dai
:
2327 case snd_soc_dapm_dai_link
:
2328 list_add(&path
->list
, &dapm
->card
->paths
);
2329 list_add(&path
->list_sink
, &wsink
->sources
);
2330 list_add(&path
->list_source
, &wsource
->sinks
);
2333 case snd_soc_dapm_mux
:
2334 case snd_soc_dapm_virt_mux
:
2335 case snd_soc_dapm_value_mux
:
2336 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2337 &wsink
->kcontrol_news
[0]);
2341 case snd_soc_dapm_switch
:
2342 case snd_soc_dapm_mixer
:
2343 case snd_soc_dapm_mixer_named_ctl
:
2344 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2348 case snd_soc_dapm_hp
:
2349 case snd_soc_dapm_mic
:
2350 case snd_soc_dapm_line
:
2351 case snd_soc_dapm_spk
:
2352 list_add(&path
->list
, &dapm
->card
->paths
);
2353 list_add(&path
->list_sink
, &wsink
->sources
);
2354 list_add(&path
->list_source
, &wsource
->sinks
);
2359 dapm_mark_dirty(wsource
, "Route added");
2360 dapm_mark_dirty(wsink
, "Route added");
2365 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2366 source
, control
, sink
);
2371 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2372 const struct snd_soc_dapm_route
*route
)
2374 struct snd_soc_dapm_path
*path
, *p
;
2377 char prefixed_sink
[80];
2378 char prefixed_source
[80];
2380 if (route
->control
) {
2382 "ASoC: Removal of routes with controls not supported\n");
2386 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2387 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2388 dapm
->codec
->name_prefix
, route
->sink
);
2389 sink
= prefixed_sink
;
2390 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2391 dapm
->codec
->name_prefix
, route
->source
);
2392 source
= prefixed_source
;
2395 source
= route
->source
;
2399 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2400 if (strcmp(p
->source
->name
, source
) != 0)
2402 if (strcmp(p
->sink
->name
, sink
) != 0)
2409 dapm_mark_dirty(path
->source
, "Route removed");
2410 dapm_mark_dirty(path
->sink
, "Route removed");
2412 dapm_free_path(path
);
2414 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
2422 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2423 * @dapm: DAPM context
2424 * @route: audio routes
2425 * @num: number of routes
2427 * Connects 2 dapm widgets together via a named audio path. The sink is
2428 * the widget receiving the audio signal, whilst the source is the sender
2429 * of the audio signal.
2431 * Returns 0 for success else error. On error all resources can be freed
2432 * with a call to snd_soc_card_free().
2434 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2435 const struct snd_soc_dapm_route
*route
, int num
)
2439 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2440 for (i
= 0; i
< num
; i
++) {
2441 r
= snd_soc_dapm_add_route(dapm
, route
);
2443 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
2445 route
->control
? route
->control
: "direct",
2451 mutex_unlock(&dapm
->card
->dapm_mutex
);
2455 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2458 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2459 * @dapm: DAPM context
2460 * @route: audio routes
2461 * @num: number of routes
2463 * Removes routes from the DAPM context.
2465 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2466 const struct snd_soc_dapm_route
*route
, int num
)
2470 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2471 for (i
= 0; i
< num
; i
++) {
2472 snd_soc_dapm_del_route(dapm
, route
);
2475 mutex_unlock(&dapm
->card
->dapm_mutex
);
2479 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2481 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2482 const struct snd_soc_dapm_route
*route
)
2484 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2487 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2490 struct snd_soc_dapm_path
*path
;
2494 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
2500 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
2505 if (route
->control
|| route
->connected
)
2506 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
2507 route
->source
, route
->sink
);
2509 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2510 if (path
->sink
== sink
) {
2517 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
2518 route
->source
, route
->sink
);
2520 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
2521 count
, route
->source
, route
->sink
);
2527 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2528 * @dapm: DAPM context
2529 * @route: audio routes
2530 * @num: number of routes
2532 * Mark existing routes matching those specified in the passed array
2533 * as being weak, meaning that they are ignored for the purpose of
2534 * power decisions. The main intended use case is for sidetone paths
2535 * which couple audio between other independent paths if they are both
2536 * active in order to make the combination work better at the user
2537 * level but which aren't intended to be "used".
2539 * Note that CODEC drivers should not use this as sidetone type paths
2540 * can frequently also be used as bypass paths.
2542 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2543 const struct snd_soc_dapm_route
*route
, int num
)
2548 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2549 for (i
= 0; i
< num
; i
++) {
2550 err
= snd_soc_dapm_weak_route(dapm
, route
);
2555 mutex_unlock(&dapm
->card
->dapm_mutex
);
2559 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2562 * snd_soc_dapm_new_widgets - add new dapm widgets
2563 * @dapm: DAPM context
2565 * Checks the codec for any new dapm widgets and creates them if found.
2567 * Returns 0 for success.
2569 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
2571 struct snd_soc_dapm_widget
*w
;
2574 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2576 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2581 if (w
->num_kcontrols
) {
2582 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2583 sizeof(struct snd_kcontrol
*),
2585 if (!w
->kcontrols
) {
2586 mutex_unlock(&dapm
->card
->dapm_mutex
);
2592 case snd_soc_dapm_switch
:
2593 case snd_soc_dapm_mixer
:
2594 case snd_soc_dapm_mixer_named_ctl
:
2597 case snd_soc_dapm_mux
:
2598 case snd_soc_dapm_virt_mux
:
2599 case snd_soc_dapm_value_mux
:
2602 case snd_soc_dapm_pga
:
2603 case snd_soc_dapm_out_drv
:
2610 /* Read the initial power state from the device */
2612 val
= soc_widget_read(w
, w
->reg
);
2613 val
&= 1 << w
->shift
;
2623 dapm_mark_dirty(w
, "new widget");
2624 dapm_debugfs_add_widget(w
);
2627 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2628 mutex_unlock(&dapm
->card
->dapm_mutex
);
2631 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2634 * snd_soc_dapm_get_volsw - dapm mixer get callback
2635 * @kcontrol: mixer control
2636 * @ucontrol: control element information
2638 * Callback to get the value of a dapm mixer control.
2640 * Returns 0 for success.
2642 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2643 struct snd_ctl_elem_value
*ucontrol
)
2645 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2646 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2647 struct soc_mixer_control
*mc
=
2648 (struct soc_mixer_control
*)kcontrol
->private_value
;
2649 unsigned int reg
= mc
->reg
;
2650 unsigned int shift
= mc
->shift
;
2652 unsigned int mask
= (1 << fls(max
)) - 1;
2653 unsigned int invert
= mc
->invert
;
2655 if (snd_soc_volsw_is_stereo(mc
))
2656 dev_warn(widget
->dapm
->dev
,
2657 "ASoC: Control '%s' is stereo, which is not supported\n",
2660 ucontrol
->value
.integer
.value
[0] =
2661 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2663 ucontrol
->value
.integer
.value
[0] =
2664 max
- ucontrol
->value
.integer
.value
[0];
2668 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2671 * snd_soc_dapm_put_volsw - dapm mixer set callback
2672 * @kcontrol: mixer control
2673 * @ucontrol: control element information
2675 * Callback to set the value of a dapm mixer control.
2677 * Returns 0 for success.
2679 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2680 struct snd_ctl_elem_value
*ucontrol
)
2682 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2683 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2684 struct snd_soc_codec
*codec
= widget
->codec
;
2685 struct snd_soc_card
*card
= codec
->card
;
2686 struct soc_mixer_control
*mc
=
2687 (struct soc_mixer_control
*)kcontrol
->private_value
;
2688 unsigned int reg
= mc
->reg
;
2689 unsigned int shift
= mc
->shift
;
2691 unsigned int mask
= (1 << fls(max
)) - 1;
2692 unsigned int invert
= mc
->invert
;
2694 int connect
, change
;
2695 struct snd_soc_dapm_update update
;
2698 if (snd_soc_volsw_is_stereo(mc
))
2699 dev_warn(widget
->dapm
->dev
,
2700 "ASoC: Control '%s' is stereo, which is not supported\n",
2703 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2708 mask
= mask
<< shift
;
2711 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2713 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2715 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2716 widget
= wlist
->widgets
[wi
];
2718 widget
->value
= val
;
2720 update
.kcontrol
= kcontrol
;
2721 update
.widget
= widget
;
2725 widget
->dapm
->update
= &update
;
2727 soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2729 widget
->dapm
->update
= NULL
;
2733 mutex_unlock(&card
->dapm_mutex
);
2736 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2739 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2740 * @kcontrol: mixer control
2741 * @ucontrol: control element information
2743 * Callback to get the value of a dapm enumerated double mixer control.
2745 * Returns 0 for success.
2747 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2748 struct snd_ctl_elem_value
*ucontrol
)
2750 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2751 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2752 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2755 val
= snd_soc_read(widget
->codec
, e
->reg
);
2756 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & e
->mask
;
2757 if (e
->shift_l
!= e
->shift_r
)
2758 ucontrol
->value
.enumerated
.item
[1] =
2759 (val
>> e
->shift_r
) & e
->mask
;
2763 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2766 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2767 * @kcontrol: mixer control
2768 * @ucontrol: control element information
2770 * Callback to set the value of a dapm enumerated double mixer control.
2772 * Returns 0 for success.
2774 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2775 struct snd_ctl_elem_value
*ucontrol
)
2777 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2778 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2779 struct snd_soc_codec
*codec
= widget
->codec
;
2780 struct snd_soc_card
*card
= codec
->card
;
2781 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2782 unsigned int val
, mux
, change
;
2784 struct snd_soc_dapm_update update
;
2787 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2789 mux
= ucontrol
->value
.enumerated
.item
[0];
2790 val
= mux
<< e
->shift_l
;
2791 mask
= e
->mask
<< e
->shift_l
;
2792 if (e
->shift_l
!= e
->shift_r
) {
2793 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2795 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2796 mask
|= e
->mask
<< e
->shift_r
;
2799 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2801 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2803 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2804 widget
= wlist
->widgets
[wi
];
2806 widget
->value
= val
;
2808 update
.kcontrol
= kcontrol
;
2809 update
.widget
= widget
;
2810 update
.reg
= e
->reg
;
2813 widget
->dapm
->update
= &update
;
2815 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2817 widget
->dapm
->update
= NULL
;
2821 mutex_unlock(&card
->dapm_mutex
);
2824 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2827 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2828 * @kcontrol: mixer control
2829 * @ucontrol: control element information
2831 * Returns 0 for success.
2833 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2834 struct snd_ctl_elem_value
*ucontrol
)
2836 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2837 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2839 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2843 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2846 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2847 * @kcontrol: mixer control
2848 * @ucontrol: control element information
2850 * Returns 0 for success.
2852 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2853 struct snd_ctl_elem_value
*ucontrol
)
2855 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2856 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2857 struct snd_soc_codec
*codec
= widget
->codec
;
2858 struct snd_soc_card
*card
= codec
->card
;
2859 struct soc_enum
*e
=
2860 (struct soc_enum
*)kcontrol
->private_value
;
2865 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2868 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2870 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2872 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2873 widget
= wlist
->widgets
[wi
];
2875 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2877 soc_dapm_mux_update_power(widget
, kcontrol
, widget
->value
, e
);
2881 mutex_unlock(&card
->dapm_mutex
);
2884 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2887 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2889 * @kcontrol: mixer control
2890 * @ucontrol: control element information
2892 * Callback to get the value of a dapm semi enumerated double mixer control.
2894 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2895 * used for handling bitfield coded enumeration for example.
2897 * Returns 0 for success.
2899 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2900 struct snd_ctl_elem_value
*ucontrol
)
2902 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2903 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2904 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2905 unsigned int reg_val
, val
, mux
;
2907 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2908 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2909 for (mux
= 0; mux
< e
->max
; mux
++) {
2910 if (val
== e
->values
[mux
])
2913 ucontrol
->value
.enumerated
.item
[0] = mux
;
2914 if (e
->shift_l
!= e
->shift_r
) {
2915 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2916 for (mux
= 0; mux
< e
->max
; mux
++) {
2917 if (val
== e
->values
[mux
])
2920 ucontrol
->value
.enumerated
.item
[1] = mux
;
2925 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2928 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2930 * @kcontrol: mixer control
2931 * @ucontrol: control element information
2933 * Callback to set the value of a dapm semi enumerated double mixer control.
2935 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2936 * used for handling bitfield coded enumeration for example.
2938 * Returns 0 for success.
2940 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2941 struct snd_ctl_elem_value
*ucontrol
)
2943 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2944 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2945 struct snd_soc_codec
*codec
= widget
->codec
;
2946 struct snd_soc_card
*card
= codec
->card
;
2947 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2948 unsigned int val
, mux
, change
;
2950 struct snd_soc_dapm_update update
;
2953 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2955 mux
= ucontrol
->value
.enumerated
.item
[0];
2956 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2957 mask
= e
->mask
<< e
->shift_l
;
2958 if (e
->shift_l
!= e
->shift_r
) {
2959 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2961 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2962 mask
|= e
->mask
<< e
->shift_r
;
2965 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2967 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2969 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2970 widget
= wlist
->widgets
[wi
];
2972 widget
->value
= val
;
2974 update
.kcontrol
= kcontrol
;
2975 update
.widget
= widget
;
2976 update
.reg
= e
->reg
;
2979 widget
->dapm
->update
= &update
;
2981 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2983 widget
->dapm
->update
= NULL
;
2987 mutex_unlock(&card
->dapm_mutex
);
2990 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2993 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2995 * @kcontrol: mixer control
2996 * @uinfo: control element information
2998 * Callback to provide information about a pin switch control.
3000 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3001 struct snd_ctl_elem_info
*uinfo
)
3003 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3005 uinfo
->value
.integer
.min
= 0;
3006 uinfo
->value
.integer
.max
= 1;
3010 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3013 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3015 * @kcontrol: mixer control
3018 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3019 struct snd_ctl_elem_value
*ucontrol
)
3021 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3022 const char *pin
= (const char *)kcontrol
->private_value
;
3024 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3026 ucontrol
->value
.integer
.value
[0] =
3027 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3029 mutex_unlock(&card
->dapm_mutex
);
3033 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3036 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3038 * @kcontrol: mixer control
3041 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3042 struct snd_ctl_elem_value
*ucontrol
)
3044 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3045 const char *pin
= (const char *)kcontrol
->private_value
;
3047 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3049 if (ucontrol
->value
.integer
.value
[0])
3050 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3052 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3054 mutex_unlock(&card
->dapm_mutex
);
3056 snd_soc_dapm_sync(&card
->dapm
);
3059 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3061 static struct snd_soc_dapm_widget
*
3062 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3063 const struct snd_soc_dapm_widget
*widget
)
3065 struct snd_soc_dapm_widget
*w
;
3069 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3073 case snd_soc_dapm_regulator_supply
:
3074 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3075 if (IS_ERR(w
->regulator
)) {
3076 ret
= PTR_ERR(w
->regulator
);
3077 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3082 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3083 ret
= regulator_allow_bypass(w
->regulator
, true);
3085 dev_warn(w
->dapm
->dev
,
3086 "ASoC: Failed to unbypass %s: %d\n",
3090 case snd_soc_dapm_clock_supply
:
3091 #ifdef CONFIG_CLKDEV_LOOKUP
3092 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3093 if (IS_ERR(w
->clk
)) {
3094 ret
= PTR_ERR(w
->clk
);
3095 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3107 name_len
= strlen(widget
->name
) + 1;
3108 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3109 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
3110 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
3111 if (w
->name
== NULL
) {
3115 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3116 snprintf((char *)w
->name
, name_len
, "%s %s",
3117 dapm
->codec
->name_prefix
, widget
->name
);
3119 snprintf((char *)w
->name
, name_len
, "%s", widget
->name
);
3122 case snd_soc_dapm_switch
:
3123 case snd_soc_dapm_mixer
:
3124 case snd_soc_dapm_mixer_named_ctl
:
3125 w
->power_check
= dapm_generic_check_power
;
3127 case snd_soc_dapm_mux
:
3128 case snd_soc_dapm_virt_mux
:
3129 case snd_soc_dapm_value_mux
:
3130 w
->power_check
= dapm_generic_check_power
;
3132 case snd_soc_dapm_adc
:
3133 case snd_soc_dapm_aif_out
:
3134 w
->power_check
= dapm_adc_check_power
;
3136 case snd_soc_dapm_dac
:
3137 case snd_soc_dapm_aif_in
:
3138 w
->power_check
= dapm_dac_check_power
;
3140 case snd_soc_dapm_pga
:
3141 case snd_soc_dapm_out_drv
:
3142 case snd_soc_dapm_input
:
3143 case snd_soc_dapm_output
:
3144 case snd_soc_dapm_micbias
:
3145 case snd_soc_dapm_spk
:
3146 case snd_soc_dapm_hp
:
3147 case snd_soc_dapm_mic
:
3148 case snd_soc_dapm_line
:
3149 case snd_soc_dapm_dai_link
:
3150 w
->power_check
= dapm_generic_check_power
;
3152 case snd_soc_dapm_supply
:
3153 case snd_soc_dapm_regulator_supply
:
3154 case snd_soc_dapm_clock_supply
:
3155 w
->power_check
= dapm_supply_check_power
;
3157 case snd_soc_dapm_dai
:
3158 w
->power_check
= dapm_dai_check_power
;
3161 w
->power_check
= dapm_always_on_check_power
;
3166 w
->codec
= dapm
->codec
;
3167 w
->platform
= dapm
->platform
;
3168 INIT_LIST_HEAD(&w
->sources
);
3169 INIT_LIST_HEAD(&w
->sinks
);
3170 INIT_LIST_HEAD(&w
->list
);
3171 INIT_LIST_HEAD(&w
->dirty
);
3172 list_add(&w
->list
, &dapm
->card
->widgets
);
3174 /* machine layer set ups unconnected pins and insertions */
3180 * snd_soc_dapm_new_controls - create new dapm controls
3181 * @dapm: DAPM context
3182 * @widget: widget array
3183 * @num: number of widgets
3185 * Creates new DAPM controls based upon the templates.
3187 * Returns 0 for success else error.
3189 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3190 const struct snd_soc_dapm_widget
*widget
,
3193 struct snd_soc_dapm_widget
*w
;
3197 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3198 for (i
= 0; i
< num
; i
++) {
3199 w
= snd_soc_dapm_new_control(dapm
, widget
);
3202 "ASoC: Failed to create DAPM control %s\n",
3209 mutex_unlock(&dapm
->card
->dapm_mutex
);
3212 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3214 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3215 struct snd_kcontrol
*kcontrol
, int event
)
3217 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3218 struct snd_soc_dai
*source
, *sink
;
3219 const struct snd_soc_pcm_stream
*config
= w
->params
;
3220 struct snd_pcm_substream substream
;
3221 struct snd_pcm_hw_params
*params
= NULL
;
3226 BUG_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
));
3228 /* We only support a single source and sink, pick the first */
3229 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3231 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3234 BUG_ON(!source_p
|| !sink_p
);
3235 BUG_ON(!sink_p
->source
|| !source_p
->sink
);
3236 BUG_ON(!source_p
->source
|| !sink_p
->sink
);
3238 source
= source_p
->source
->priv
;
3239 sink
= sink_p
->sink
->priv
;
3241 /* Be a little careful as we don't want to overflow the mask array */
3242 if (config
->formats
) {
3243 fmt
= ffs(config
->formats
) - 1;
3245 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3250 /* Currently very limited parameter selection */
3251 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3256 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3258 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3260 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3263 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3264 = config
->channels_min
;
3265 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3266 = config
->channels_max
;
3268 memset(&substream
, 0, sizeof(substream
));
3271 case SND_SOC_DAPM_PRE_PMU
:
3272 if (source
->driver
->ops
&& source
->driver
->ops
->hw_params
) {
3273 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3274 ret
= source
->driver
->ops
->hw_params(&substream
,
3277 dev_err(source
->dev
,
3278 "ASoC: hw_params() failed: %d\n", ret
);
3283 if (sink
->driver
->ops
&& sink
->driver
->ops
->hw_params
) {
3284 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3285 ret
= sink
->driver
->ops
->hw_params(&substream
, params
,
3289 "ASoC: hw_params() failed: %d\n", ret
);
3295 case SND_SOC_DAPM_POST_PMU
:
3296 ret
= snd_soc_dai_digital_mute(sink
, 0,
3297 SNDRV_PCM_STREAM_PLAYBACK
);
3298 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3299 dev_warn(sink
->dev
, "ASoC: Failed to unmute: %d\n", ret
);
3303 case SND_SOC_DAPM_PRE_PMD
:
3304 ret
= snd_soc_dai_digital_mute(sink
, 1,
3305 SNDRV_PCM_STREAM_PLAYBACK
);
3306 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3307 dev_warn(sink
->dev
, "ASoC: Failed to mute: %d\n", ret
);
3321 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3322 const struct snd_soc_pcm_stream
*params
,
3323 struct snd_soc_dapm_widget
*source
,
3324 struct snd_soc_dapm_widget
*sink
)
3326 struct snd_soc_dapm_route routes
[2];
3327 struct snd_soc_dapm_widget
template;
3328 struct snd_soc_dapm_widget
*w
;
3332 len
= strlen(source
->name
) + strlen(sink
->name
) + 2;
3333 link_name
= devm_kzalloc(card
->dev
, len
, GFP_KERNEL
);
3336 snprintf(link_name
, len
, "%s-%s", source
->name
, sink
->name
);
3338 memset(&template, 0, sizeof(template));
3339 template.reg
= SND_SOC_NOPM
;
3340 template.id
= snd_soc_dapm_dai_link
;
3341 template.name
= link_name
;
3342 template.event
= snd_soc_dai_link_event
;
3343 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3344 SND_SOC_DAPM_PRE_PMD
;
3346 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
3348 w
= snd_soc_dapm_new_control(&card
->dapm
, &template);
3350 dev_err(card
->dev
, "ASoC: Failed to create %s widget\n",
3357 memset(&routes
, 0, sizeof(routes
));
3359 routes
[0].source
= source
->name
;
3360 routes
[0].sink
= link_name
;
3361 routes
[1].source
= link_name
;
3362 routes
[1].sink
= sink
->name
;
3364 return snd_soc_dapm_add_routes(&card
->dapm
, routes
,
3365 ARRAY_SIZE(routes
));
3368 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3369 struct snd_soc_dai
*dai
)
3371 struct snd_soc_dapm_widget
template;
3372 struct snd_soc_dapm_widget
*w
;
3374 WARN_ON(dapm
->dev
!= dai
->dev
);
3376 memset(&template, 0, sizeof(template));
3377 template.reg
= SND_SOC_NOPM
;
3379 if (dai
->driver
->playback
.stream_name
) {
3380 template.id
= snd_soc_dapm_dai
;
3381 template.name
= dai
->driver
->playback
.stream_name
;
3382 template.sname
= dai
->driver
->playback
.stream_name
;
3384 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3387 w
= snd_soc_dapm_new_control(dapm
, &template);
3389 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3390 dai
->driver
->playback
.stream_name
);
3394 dai
->playback_widget
= w
;
3397 if (dai
->driver
->capture
.stream_name
) {
3398 template.id
= snd_soc_dapm_dai
;
3399 template.name
= dai
->driver
->capture
.stream_name
;
3400 template.sname
= dai
->driver
->capture
.stream_name
;
3402 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3405 w
= snd_soc_dapm_new_control(dapm
, &template);
3407 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3408 dai
->driver
->capture
.stream_name
);
3412 dai
->capture_widget
= w
;
3418 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3420 struct snd_soc_dapm_widget
*dai_w
, *w
;
3421 struct snd_soc_dai
*dai
;
3422 struct snd_soc_dapm_route r
;
3424 memset(&r
, 0, sizeof(r
));
3426 /* For each DAI widget... */
3427 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3428 if (dai_w
->id
!= snd_soc_dapm_dai
)
3433 /* ...find all widgets with the same stream and link them */
3434 list_for_each_entry(w
, &card
->widgets
, list
) {
3435 if (w
->dapm
!= dai_w
->dapm
)
3438 if (w
->id
== snd_soc_dapm_dai
)
3444 if (dai
->driver
->playback
.stream_name
&&
3446 dai
->driver
->playback
.stream_name
)) {
3447 r
.source
= dai
->playback_widget
->name
;
3449 dev_dbg(dai
->dev
, "%s -> %s\n",
3452 snd_soc_dapm_add_route(w
->dapm
, &r
);
3455 if (dai
->driver
->capture
.stream_name
&&
3457 dai
->driver
->capture
.stream_name
)) {
3459 r
.sink
= dai
->capture_widget
->name
;
3460 dev_dbg(dai
->dev
, "%s -> %s\n",
3463 snd_soc_dapm_add_route(w
->dapm
, &r
);
3471 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3475 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
3476 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3477 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
3479 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3480 w_cpu
= cpu_dai
->playback_widget
;
3481 w_codec
= codec_dai
->playback_widget
;
3483 w_cpu
= cpu_dai
->capture_widget
;
3484 w_codec
= codec_dai
->capture_widget
;
3489 dapm_mark_dirty(w_cpu
, "stream event");
3492 case SND_SOC_DAPM_STREAM_START
:
3495 case SND_SOC_DAPM_STREAM_STOP
:
3498 case SND_SOC_DAPM_STREAM_SUSPEND
:
3499 case SND_SOC_DAPM_STREAM_RESUME
:
3500 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3501 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3508 dapm_mark_dirty(w_codec
, "stream event");
3511 case SND_SOC_DAPM_STREAM_START
:
3512 w_codec
->active
= 1;
3514 case SND_SOC_DAPM_STREAM_STOP
:
3515 w_codec
->active
= 0;
3517 case SND_SOC_DAPM_STREAM_SUSPEND
:
3518 case SND_SOC_DAPM_STREAM_RESUME
:
3519 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3520 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3525 dapm_power_widgets(&rtd
->card
->dapm
, event
);
3529 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3530 * @rtd: PCM runtime data
3531 * @stream: stream name
3532 * @event: stream event
3534 * Sends a stream event to the dapm core. The core then makes any
3535 * necessary widget power changes.
3537 * Returns 0 for success else error.
3539 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3542 struct snd_soc_card
*card
= rtd
->card
;
3544 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3545 soc_dapm_stream_event(rtd
, stream
, event
);
3546 mutex_unlock(&card
->dapm_mutex
);
3550 * snd_soc_dapm_enable_pin - enable pin.
3551 * @dapm: DAPM context
3554 * Enables input/output pin and its parents or children widgets iff there is
3555 * a valid audio route and active audio stream.
3556 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3557 * do any widget power switching.
3559 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3561 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3563 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3566 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3567 * @dapm: DAPM context
3570 * Enables input/output pin regardless of any other state. This is
3571 * intended for use with microphone bias supplies used in microphone
3574 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3575 * do any widget power switching.
3577 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3580 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3583 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
3587 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
3590 dapm_mark_dirty(w
, "force enable");
3594 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3597 * snd_soc_dapm_disable_pin - disable pin.
3598 * @dapm: DAPM context
3601 * Disables input/output pin and its parents or children widgets.
3602 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3603 * do any widget power switching.
3605 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3608 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3610 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3613 * snd_soc_dapm_nc_pin - permanently disable pin.
3614 * @dapm: DAPM context
3617 * Marks the specified pin as being not connected, disabling it along
3618 * any parent or child widgets. At present this is identical to
3619 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3620 * additional things such as disabling controls which only affect
3621 * paths through the pin.
3623 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3624 * do any widget power switching.
3626 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3628 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3630 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3633 * snd_soc_dapm_get_pin_status - get audio pin status
3634 * @dapm: DAPM context
3635 * @pin: audio signal pin endpoint (or start point)
3637 * Get audio pin status - connected or disconnected.
3639 * Returns 1 for connected otherwise 0.
3641 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3644 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3647 return w
->connected
;
3651 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
3654 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3655 * @dapm: DAPM context
3656 * @pin: audio signal pin endpoint (or start point)
3658 * Mark the given endpoint or pin as ignoring suspend. When the
3659 * system is disabled a path between two endpoints flagged as ignoring
3660 * suspend will not be disabled. The path must already be enabled via
3661 * normal means at suspend time, it will not be turned on if it was not
3664 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
3667 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
3670 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
3674 w
->ignore_suspend
= 1;
3678 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
3680 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
3681 struct snd_soc_dapm_widget
*w
)
3683 struct snd_soc_dapm_path
*p
;
3685 list_for_each_entry(p
, &card
->paths
, list
) {
3686 if ((p
->source
== w
) || (p
->sink
== w
)) {
3688 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3689 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
3690 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
3692 /* Connected to something other than the codec */
3693 if (p
->source
->dapm
!= p
->sink
->dapm
)
3696 * Loopback connection from codec external pin to
3697 * codec external pin
3699 if (p
->sink
->id
== snd_soc_dapm_input
) {
3700 switch (p
->source
->id
) {
3701 case snd_soc_dapm_output
:
3702 case snd_soc_dapm_micbias
:
3715 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3716 * @codec: The codec whose pins should be processed
3718 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3719 * which are unused. Pins are used if they are connected externally to the
3720 * codec, whether that be to some other device, or a loop-back connection to
3723 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
3725 struct snd_soc_card
*card
= codec
->card
;
3726 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3727 struct snd_soc_dapm_widget
*w
;
3729 dev_dbg(codec
->dev
, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n",
3730 &card
->dapm
, &codec
->dapm
);
3732 list_for_each_entry(w
, &card
->widgets
, list
) {
3733 if (w
->dapm
!= dapm
)
3736 case snd_soc_dapm_input
:
3737 case snd_soc_dapm_output
:
3738 case snd_soc_dapm_micbias
:
3739 dev_dbg(codec
->dev
, "ASoC: Auto NC: Checking widget %s\n",
3741 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
3743 "... Not in map; disabling\n");
3744 snd_soc_dapm_nc_pin(dapm
, w
->name
);
3754 * snd_soc_dapm_free - free dapm resources
3755 * @dapm: DAPM context
3757 * Free all dapm widgets and resources.
3759 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
3761 snd_soc_dapm_sys_remove(dapm
->dev
);
3762 dapm_debugfs_cleanup(dapm
);
3763 dapm_free_widgets(dapm
);
3764 list_del(&dapm
->list
);
3766 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
3768 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
3770 struct snd_soc_card
*card
= dapm
->card
;
3771 struct snd_soc_dapm_widget
*w
;
3772 LIST_HEAD(down_list
);
3775 mutex_lock(&card
->dapm_mutex
);
3777 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
3778 if (w
->dapm
!= dapm
)
3781 dapm_seq_insert(w
, &down_list
, false);
3787 /* If there were no widgets to power down we're already in
3791 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
3792 snd_soc_dapm_set_bias_level(dapm
,
3793 SND_SOC_BIAS_PREPARE
);
3794 dapm_seq_run(dapm
, &down_list
, 0, false);
3795 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
3796 snd_soc_dapm_set_bias_level(dapm
,
3797 SND_SOC_BIAS_STANDBY
);
3800 mutex_unlock(&card
->dapm_mutex
);
3804 * snd_soc_dapm_shutdown - callback for system shutdown
3806 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
3808 struct snd_soc_codec
*codec
;
3810 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
3811 soc_dapm_shutdown_codec(&codec
->dapm
);
3812 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
3813 snd_soc_dapm_set_bias_level(&codec
->dapm
,
3818 /* Module information */
3819 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3820 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3821 MODULE_LICENSE("GPL");