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 /* create a new dapm widget */
145 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
146 const struct snd_soc_dapm_widget
*_widget
)
148 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
151 /* get snd_card from DAPM context */
152 static inline struct snd_card
*dapm_get_snd_card(
153 struct snd_soc_dapm_context
*dapm
)
156 return dapm
->codec
->card
->snd_card
;
157 else if (dapm
->platform
)
158 return dapm
->platform
->card
->snd_card
;
166 /* get soc_card from DAPM context */
167 static inline struct snd_soc_card
*dapm_get_soc_card(
168 struct snd_soc_dapm_context
*dapm
)
171 return dapm
->codec
->card
;
172 else if (dapm
->platform
)
173 return dapm
->platform
->card
;
181 static void dapm_reset(struct snd_soc_card
*card
)
183 struct snd_soc_dapm_widget
*w
;
185 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
187 list_for_each_entry(w
, &card
->widgets
, list
) {
188 w
->power_checked
= false;
194 static int soc_widget_read(struct snd_soc_dapm_widget
*w
, int reg
)
197 return snd_soc_read(w
->codec
, reg
);
198 else if (w
->platform
)
199 return snd_soc_platform_read(w
->platform
, reg
);
201 dev_err(w
->dapm
->dev
, "no valid widget read method\n");
205 static int soc_widget_write(struct snd_soc_dapm_widget
*w
, int reg
, int val
)
208 return snd_soc_write(w
->codec
, reg
, val
);
209 else if (w
->platform
)
210 return snd_soc_platform_write(w
->platform
, reg
, val
);
212 dev_err(w
->dapm
->dev
, "no valid widget write method\n");
216 static inline void soc_widget_lock(struct snd_soc_dapm_widget
*w
)
218 if (w
->codec
&& !w
->codec
->using_regmap
)
219 mutex_lock(&w
->codec
->mutex
);
220 else if (w
->platform
)
221 mutex_lock(&w
->platform
->mutex
);
224 static inline void soc_widget_unlock(struct snd_soc_dapm_widget
*w
)
226 if (w
->codec
&& !w
->codec
->using_regmap
)
227 mutex_unlock(&w
->codec
->mutex
);
228 else if (w
->platform
)
229 mutex_unlock(&w
->platform
->mutex
);
232 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget
*w
,
233 unsigned short reg
, unsigned int mask
, unsigned int value
)
236 unsigned int old
, new;
239 if (w
->codec
&& w
->codec
->using_regmap
) {
240 ret
= regmap_update_bits_check(w
->codec
->control_data
,
241 reg
, mask
, value
, &change
);
246 ret
= soc_widget_read(w
, reg
);
248 soc_widget_unlock(w
);
253 new = (old
& ~mask
) | (value
& mask
);
256 ret
= soc_widget_write(w
, reg
, new);
258 soc_widget_unlock(w
);
262 soc_widget_unlock(w
);
269 * snd_soc_dapm_set_bias_level - set the bias level for the system
270 * @dapm: DAPM context
271 * @level: level to configure
273 * Configure the bias (power) levels for the SoC audio device.
275 * Returns 0 for success else error.
277 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
278 enum snd_soc_bias_level level
)
280 struct snd_soc_card
*card
= dapm
->card
;
283 trace_snd_soc_bias_level_start(card
, level
);
285 if (card
&& card
->set_bias_level
)
286 ret
= card
->set_bias_level(card
, dapm
, level
);
291 if (dapm
->codec
->driver
->set_bias_level
)
292 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
295 dapm
->bias_level
= level
;
296 } else if (!card
|| dapm
!= &card
->dapm
) {
297 dapm
->bias_level
= level
;
303 if (card
&& card
->set_bias_level_post
)
304 ret
= card
->set_bias_level_post(card
, dapm
, level
);
306 trace_snd_soc_bias_level_done(card
, level
);
311 /* set up initial codec paths */
312 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
313 struct snd_soc_dapm_path
*p
, int i
)
316 case snd_soc_dapm_switch
:
317 case snd_soc_dapm_mixer
:
318 case snd_soc_dapm_mixer_named_ctl
: {
320 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
321 w
->kcontrol_news
[i
].private_value
;
322 unsigned int reg
= mc
->reg
;
323 unsigned int shift
= mc
->shift
;
325 unsigned int mask
= (1 << fls(max
)) - 1;
326 unsigned int invert
= mc
->invert
;
328 val
= soc_widget_read(w
, reg
);
329 val
= (val
>> shift
) & mask
;
336 case snd_soc_dapm_mux
: {
337 struct soc_enum
*e
= (struct soc_enum
*)
338 w
->kcontrol_news
[i
].private_value
;
339 int val
, item
, bitmask
;
341 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
343 val
= soc_widget_read(w
, e
->reg
);
344 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
347 for (i
= 0; i
< e
->max
; i
++) {
348 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
353 case snd_soc_dapm_virt_mux
: {
354 struct soc_enum
*e
= (struct soc_enum
*)
355 w
->kcontrol_news
[i
].private_value
;
358 /* since a virtual mux has no backing registers to
359 * decide which path to connect, it will try to match
360 * with the first enumeration. This is to ensure
361 * that the default mux choice (the first) will be
362 * correctly powered up during initialization.
364 if (!strcmp(p
->name
, e
->texts
[0]))
368 case snd_soc_dapm_value_mux
: {
369 struct soc_enum
*e
= (struct soc_enum
*)
370 w
->kcontrol_news
[i
].private_value
;
373 val
= soc_widget_read(w
, e
->reg
);
374 val
= (val
>> e
->shift_l
) & e
->mask
;
375 for (item
= 0; item
< e
->max
; item
++) {
376 if (val
== e
->values
[item
])
381 for (i
= 0; i
< e
->max
; i
++) {
382 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
387 /* does not affect routing - always connected */
388 case snd_soc_dapm_pga
:
389 case snd_soc_dapm_out_drv
:
390 case snd_soc_dapm_output
:
391 case snd_soc_dapm_adc
:
392 case snd_soc_dapm_input
:
393 case snd_soc_dapm_siggen
:
394 case snd_soc_dapm_dac
:
395 case snd_soc_dapm_micbias
:
396 case snd_soc_dapm_vmid
:
397 case snd_soc_dapm_supply
:
398 case snd_soc_dapm_regulator_supply
:
399 case snd_soc_dapm_clock_supply
:
400 case snd_soc_dapm_aif_in
:
401 case snd_soc_dapm_aif_out
:
402 case snd_soc_dapm_dai
:
403 case snd_soc_dapm_hp
:
404 case snd_soc_dapm_mic
:
405 case snd_soc_dapm_spk
:
406 case snd_soc_dapm_line
:
407 case snd_soc_dapm_dai_link
:
410 /* does affect routing - dynamically connected */
411 case snd_soc_dapm_pre
:
412 case snd_soc_dapm_post
:
418 /* connect mux widget to its interconnecting audio paths */
419 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
420 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
421 struct snd_soc_dapm_path
*path
, const char *control_name
,
422 const struct snd_kcontrol_new
*kcontrol
)
424 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
427 for (i
= 0; i
< e
->max
; i
++) {
428 if (!(strcmp(control_name
, e
->texts
[i
]))) {
429 list_add(&path
->list
, &dapm
->card
->paths
);
430 list_add(&path
->list_sink
, &dest
->sources
);
431 list_add(&path
->list_source
, &src
->sinks
);
432 path
->name
= (char*)e
->texts
[i
];
433 dapm_set_path_status(dest
, path
, 0);
441 /* connect mixer widget to its interconnecting audio paths */
442 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
443 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
444 struct snd_soc_dapm_path
*path
, const char *control_name
)
448 /* search for mixer kcontrol */
449 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
450 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
451 list_add(&path
->list
, &dapm
->card
->paths
);
452 list_add(&path
->list_sink
, &dest
->sources
);
453 list_add(&path
->list_source
, &src
->sinks
);
454 path
->name
= dest
->kcontrol_news
[i
].name
;
455 dapm_set_path_status(dest
, path
, i
);
462 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
463 struct snd_soc_dapm_widget
*kcontrolw
,
464 const struct snd_kcontrol_new
*kcontrol_new
,
465 struct snd_kcontrol
**kcontrol
)
467 struct snd_soc_dapm_widget
*w
;
472 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
473 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
475 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
476 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
478 *kcontrol
= w
->kcontrols
[i
];
487 /* create new dapm mixer control */
488 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
490 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
492 size_t name_len
, prefix_len
;
493 struct snd_soc_dapm_path
*path
;
494 struct snd_card
*card
= dapm
->card
->snd_card
;
496 struct snd_soc_dapm_widget_list
*wlist
;
500 prefix
= dapm
->codec
->name_prefix
;
505 prefix_len
= strlen(prefix
) + 1;
510 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
513 list_for_each_entry(path
, &w
->sources
, list_sink
) {
515 /* mixer/mux paths name must match control name */
516 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
519 if (w
->kcontrols
[i
]) {
520 path
->kcontrol
= w
->kcontrols
[i
];
524 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
525 sizeof(struct snd_soc_dapm_widget
*),
526 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
529 "asoc: can't allocate widget list for %s\n",
533 wlist
->num_widgets
= 1;
534 wlist
->widgets
[0] = w
;
536 /* add dapm control with long name.
537 * for dapm_mixer this is the concatenation of the
538 * mixer and kcontrol name.
539 * for dapm_mixer_named_ctl this is simply the
542 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
543 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
544 name_len
+= 1 + strlen(w
->name
);
546 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
548 if (path
->long_name
== NULL
) {
555 /* The control will get a prefix from
556 * the control creation process but
557 * we're also using the same prefix
558 * for widgets so cut the prefix off
559 * the front of the widget name.
561 snprintf((char *)path
->long_name
, name_len
,
562 "%s %s", w
->name
+ prefix_len
,
563 w
->kcontrol_news
[i
].name
);
565 case snd_soc_dapm_mixer_named_ctl
:
566 snprintf((char *)path
->long_name
, name_len
,
567 "%s", w
->kcontrol_news
[i
].name
);
571 ((char *)path
->long_name
)[name_len
- 1] = '\0';
573 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
574 wlist
, path
->long_name
,
576 ret
= snd_ctl_add(card
, path
->kcontrol
);
579 "asoc: failed to add dapm kcontrol %s: %d\n",
580 path
->long_name
, ret
);
582 kfree(path
->long_name
);
583 path
->long_name
= NULL
;
586 w
->kcontrols
[i
] = path
->kcontrol
;
592 /* create new dapm mux control */
593 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
595 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
596 struct snd_soc_dapm_path
*path
= NULL
;
597 struct snd_kcontrol
*kcontrol
;
598 struct snd_card
*card
= dapm
->card
->snd_card
;
602 struct snd_soc_dapm_widget_list
*wlist
;
603 int shared
, wlistentries
;
607 if (w
->num_kcontrols
!= 1) {
609 "asoc: mux %s has incorrect number of controls\n",
614 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
617 wlist
= kcontrol
->private_data
;
618 wlistentries
= wlist
->num_widgets
+ 1;
623 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
624 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
625 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
628 "asoc: can't allocate widget list for %s\n", w
->name
);
631 wlist
->num_widgets
= wlistentries
;
632 wlist
->widgets
[wlistentries
- 1] = w
;
636 prefix
= dapm
->codec
->name_prefix
;
641 name
= w
->kcontrol_news
[0].name
;
646 prefix_len
= strlen(prefix
) + 1;
652 * The control will get a prefix from the control creation
653 * process but we're also using the same prefix for widgets so
654 * cut the prefix off the front of the widget name.
656 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
657 name
+ prefix_len
, prefix
);
658 ret
= snd_ctl_add(card
, kcontrol
);
660 dev_err(dapm
->dev
, "failed to add kcontrol %s: %d\n",
667 kcontrol
->private_data
= wlist
;
669 w
->kcontrols
[0] = kcontrol
;
671 list_for_each_entry(path
, &w
->sources
, list_sink
)
672 path
->kcontrol
= kcontrol
;
677 /* create new dapm volume control */
678 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
680 if (w
->num_kcontrols
)
681 dev_err(w
->dapm
->dev
,
682 "asoc: PGA controls not supported: '%s'\n", w
->name
);
687 /* reset 'walked' bit for each dapm path */
688 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
690 struct snd_soc_dapm_path
*p
;
692 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
696 /* We implement power down on suspend by checking the power state of
697 * the ALSA card - when we are suspending the ALSA state for the card
700 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
702 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
705 case SNDRV_CTL_POWER_D3hot
:
706 case SNDRV_CTL_POWER_D3cold
:
707 if (widget
->ignore_suspend
)
708 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
710 return widget
->ignore_suspend
;
716 /* add widget to list if it's not already in the list */
717 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
718 struct snd_soc_dapm_widget
*w
)
720 struct snd_soc_dapm_widget_list
*wlist
;
721 int wlistsize
, wlistentries
, i
;
728 /* is this widget already in the list */
729 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
730 if (wlist
->widgets
[i
] == w
)
734 /* allocate some new space */
735 wlistentries
= wlist
->num_widgets
+ 1;
736 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
737 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
738 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
740 dev_err(w
->dapm
->dev
, "can't allocate widget list for %s\n",
746 /* insert the widget */
747 dev_dbg(w
->dapm
->dev
, "added %s in widget list pos %d\n",
748 w
->name
, wlist
->num_widgets
);
750 wlist
->widgets
[wlist
->num_widgets
] = w
;
751 wlist
->num_widgets
++;
756 * Recursively check for a completed path to an active or physically connected
757 * output widget. Returns number of complete paths.
759 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
760 struct snd_soc_dapm_widget_list
**list
)
762 struct snd_soc_dapm_path
*path
;
765 if (widget
->outputs
>= 0)
766 return widget
->outputs
;
768 DAPM_UPDATE_STAT(widget
, path_checks
);
770 switch (widget
->id
) {
771 case snd_soc_dapm_supply
:
772 case snd_soc_dapm_regulator_supply
:
773 case snd_soc_dapm_clock_supply
:
779 switch (widget
->id
) {
780 case snd_soc_dapm_adc
:
781 case snd_soc_dapm_aif_out
:
782 case snd_soc_dapm_dai
:
783 if (widget
->active
) {
784 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
785 return widget
->outputs
;
791 if (widget
->connected
) {
792 /* connected pin ? */
793 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
794 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
795 return widget
->outputs
;
798 /* connected jack or spk ? */
799 if (widget
->id
== snd_soc_dapm_hp
||
800 widget
->id
== snd_soc_dapm_spk
||
801 (widget
->id
== snd_soc_dapm_line
&&
802 !list_empty(&widget
->sources
))) {
803 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
804 return widget
->outputs
;
808 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
809 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
817 trace_snd_soc_dapm_output_path(widget
, path
);
819 if (path
->sink
&& path
->connect
) {
822 /* do we need to add this widget to the list ? */
825 err
= dapm_list_add_widget(list
, path
->sink
);
827 dev_err(widget
->dapm
->dev
, "could not add widget %s\n",
833 con
+= is_connected_output_ep(path
->sink
, list
);
837 widget
->outputs
= con
;
843 * Recursively check for a completed path to an active or physically connected
844 * input widget. Returns number of complete paths.
846 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
847 struct snd_soc_dapm_widget_list
**list
)
849 struct snd_soc_dapm_path
*path
;
852 if (widget
->inputs
>= 0)
853 return widget
->inputs
;
855 DAPM_UPDATE_STAT(widget
, path_checks
);
857 switch (widget
->id
) {
858 case snd_soc_dapm_supply
:
859 case snd_soc_dapm_regulator_supply
:
860 case snd_soc_dapm_clock_supply
:
866 /* active stream ? */
867 switch (widget
->id
) {
868 case snd_soc_dapm_dac
:
869 case snd_soc_dapm_aif_in
:
870 case snd_soc_dapm_dai
:
871 if (widget
->active
) {
872 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
873 return widget
->inputs
;
879 if (widget
->connected
) {
880 /* connected pin ? */
881 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
882 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
883 return widget
->inputs
;
886 /* connected VMID/Bias for lower pops */
887 if (widget
->id
== snd_soc_dapm_vmid
) {
888 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
889 return widget
->inputs
;
892 /* connected jack ? */
893 if (widget
->id
== snd_soc_dapm_mic
||
894 (widget
->id
== snd_soc_dapm_line
&&
895 !list_empty(&widget
->sinks
))) {
896 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
897 return widget
->inputs
;
900 /* signal generator */
901 if (widget
->id
== snd_soc_dapm_siggen
) {
902 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
903 return widget
->inputs
;
907 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
908 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
916 trace_snd_soc_dapm_input_path(widget
, path
);
918 if (path
->source
&& path
->connect
) {
921 /* do we need to add this widget to the list ? */
924 err
= dapm_list_add_widget(list
, path
->source
);
926 dev_err(widget
->dapm
->dev
, "could not add widget %s\n",
932 con
+= is_connected_input_ep(path
->source
, list
);
936 widget
->inputs
= con
;
942 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
944 * @stream: stream direction.
945 * @list: list of active widgets for this stream.
947 * Queries DAPM graph as to whether an valid audio stream path exists for
948 * the initial stream specified by name. This takes into account
949 * current mixer and mux kcontrol settings. Creates list of valid widgets.
951 * Returns the number of valid paths or negative error.
953 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
954 struct snd_soc_dapm_widget_list
**list
)
956 struct snd_soc_card
*card
= dai
->card
;
959 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
962 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
963 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
965 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
967 trace_snd_soc_dapm_connected(paths
, stream
);
968 dapm_clear_walk(&card
->dapm
);
969 mutex_unlock(&card
->dapm_mutex
);
975 * Handler for generic register modifier widget.
977 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
978 struct snd_kcontrol
*kcontrol
, int event
)
982 if (SND_SOC_DAPM_EVENT_ON(event
))
987 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
988 w
->mask
<< w
->shift
, val
<< w
->shift
);
992 EXPORT_SYMBOL_GPL(dapm_reg_event
);
995 * Handler for regulator supply widget.
997 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
998 struct snd_kcontrol
*kcontrol
, int event
)
1000 if (SND_SOC_DAPM_EVENT_ON(event
))
1001 return regulator_enable(w
->regulator
);
1003 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1005 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1008 * Handler for clock supply widget.
1010 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1011 struct snd_kcontrol
*kcontrol
, int event
)
1016 #ifdef CONFIG_HAVE_CLK
1017 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1018 return clk_enable(w
->clk
);
1020 clk_disable(w
->clk
);
1026 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1028 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1030 if (w
->power_checked
)
1031 return w
->new_power
;
1036 w
->new_power
= w
->power_check(w
);
1038 w
->power_checked
= true;
1040 return w
->new_power
;
1043 /* Generic check to see if a widget should be powered.
1045 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1049 DAPM_UPDATE_STAT(w
, power_checks
);
1051 in
= is_connected_input_ep(w
, NULL
);
1052 dapm_clear_walk(w
->dapm
);
1053 out
= is_connected_output_ep(w
, NULL
);
1054 dapm_clear_walk(w
->dapm
);
1055 return out
!= 0 && in
!= 0;
1058 static int dapm_dai_check_power(struct snd_soc_dapm_widget
*w
)
1060 DAPM_UPDATE_STAT(w
, power_checks
);
1065 return dapm_generic_check_power(w
);
1068 /* Check to see if an ADC has power */
1069 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
1073 DAPM_UPDATE_STAT(w
, power_checks
);
1076 in
= is_connected_input_ep(w
, NULL
);
1077 dapm_clear_walk(w
->dapm
);
1080 return dapm_generic_check_power(w
);
1084 /* Check to see if a DAC has power */
1085 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
1089 DAPM_UPDATE_STAT(w
, power_checks
);
1092 out
= is_connected_output_ep(w
, NULL
);
1093 dapm_clear_walk(w
->dapm
);
1096 return dapm_generic_check_power(w
);
1100 /* Check to see if a power supply is needed */
1101 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1103 struct snd_soc_dapm_path
*path
;
1105 DAPM_UPDATE_STAT(w
, power_checks
);
1107 /* Check if one of our outputs is connected */
1108 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1109 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1114 if (path
->connected
&&
1115 !path
->connected(path
->source
, path
->sink
))
1121 if (dapm_widget_power_check(path
->sink
))
1125 dapm_clear_walk(w
->dapm
);
1130 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1135 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1136 struct snd_soc_dapm_widget
*b
,
1144 sort
= dapm_down_seq
;
1146 if (sort
[a
->id
] != sort
[b
->id
])
1147 return sort
[a
->id
] - sort
[b
->id
];
1148 if (a
->subseq
!= b
->subseq
) {
1150 return a
->subseq
- b
->subseq
;
1152 return b
->subseq
- a
->subseq
;
1154 if (a
->reg
!= b
->reg
)
1155 return a
->reg
- b
->reg
;
1156 if (a
->dapm
!= b
->dapm
)
1157 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1162 /* Insert a widget in order into a DAPM power sequence. */
1163 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1164 struct list_head
*list
,
1167 struct snd_soc_dapm_widget
*w
;
1169 list_for_each_entry(w
, list
, power_list
)
1170 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1171 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1175 list_add_tail(&new_widget
->power_list
, list
);
1178 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
1179 struct snd_soc_dapm_widget
*w
, int event
)
1181 struct snd_soc_card
*card
= dapm
->card
;
1182 const char *ev_name
;
1186 case SND_SOC_DAPM_PRE_PMU
:
1187 ev_name
= "PRE_PMU";
1190 case SND_SOC_DAPM_POST_PMU
:
1191 ev_name
= "POST_PMU";
1194 case SND_SOC_DAPM_PRE_PMD
:
1195 ev_name
= "PRE_PMD";
1198 case SND_SOC_DAPM_POST_PMD
:
1199 ev_name
= "POST_PMD";
1207 if (w
->power
!= power
)
1210 if (w
->event
&& (w
->event_flags
& event
)) {
1211 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1213 trace_snd_soc_dapm_widget_event_start(w
, event
);
1214 ret
= w
->event(w
, NULL
, event
);
1215 trace_snd_soc_dapm_widget_event_done(w
, event
);
1217 pr_err("%s: %s event failed: %d\n",
1218 ev_name
, w
->name
, ret
);
1222 /* Apply the coalesced changes from a DAPM sequence */
1223 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
1224 struct list_head
*pending
)
1226 struct snd_soc_card
*card
= dapm
->card
;
1227 struct snd_soc_dapm_widget
*w
;
1229 unsigned int value
= 0;
1230 unsigned int mask
= 0;
1231 unsigned int cur_mask
;
1233 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1236 list_for_each_entry(w
, pending
, power_list
) {
1237 cur_mask
= 1 << w
->shift
;
1238 BUG_ON(reg
!= w
->reg
);
1249 pop_dbg(dapm
->dev
, card
->pop_time
,
1250 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1251 w
->name
, reg
, value
, mask
);
1253 /* Check for events */
1254 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
1255 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
1259 /* Any widget will do, they should all be updating the
1262 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1265 pop_dbg(dapm
->dev
, card
->pop_time
,
1266 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1267 value
, mask
, reg
, card
->pop_time
);
1268 pop_wait(card
->pop_time
);
1269 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1272 list_for_each_entry(w
, pending
, power_list
) {
1273 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
1274 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
1278 /* Apply a DAPM power sequence.
1280 * We walk over a pre-sorted list of widgets to apply power to. In
1281 * order to minimise the number of writes to the device required
1282 * multiple widgets will be updated in a single write where possible.
1283 * Currently anything that requires more than a single write is not
1286 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
1287 struct list_head
*list
, int event
, bool power_up
)
1289 struct snd_soc_dapm_widget
*w
, *n
;
1292 int cur_subseq
= -1;
1293 int cur_reg
= SND_SOC_NOPM
;
1294 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1301 sort
= dapm_down_seq
;
1303 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1306 /* Do we need to apply any queued changes? */
1307 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1308 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1309 if (!list_empty(&pending
))
1310 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1312 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1313 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1314 if (sort
[i
] == cur_sort
)
1315 cur_dapm
->seq_notifier(cur_dapm
,
1320 INIT_LIST_HEAD(&pending
);
1322 cur_subseq
= INT_MIN
;
1323 cur_reg
= SND_SOC_NOPM
;
1328 case snd_soc_dapm_pre
:
1330 list_for_each_entry_safe_continue(w
, n
, list
,
1333 if (event
== SND_SOC_DAPM_STREAM_START
)
1335 NULL
, SND_SOC_DAPM_PRE_PMU
);
1336 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1338 NULL
, SND_SOC_DAPM_PRE_PMD
);
1341 case snd_soc_dapm_post
:
1343 list_for_each_entry_safe_continue(w
, n
, list
,
1346 if (event
== SND_SOC_DAPM_STREAM_START
)
1348 NULL
, SND_SOC_DAPM_POST_PMU
);
1349 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1351 NULL
, SND_SOC_DAPM_POST_PMD
);
1355 /* Queue it up for application */
1356 cur_sort
= sort
[w
->id
];
1357 cur_subseq
= w
->subseq
;
1360 list_move(&w
->power_list
, &pending
);
1365 dev_err(w
->dapm
->dev
,
1366 "Failed to apply widget power: %d\n", ret
);
1369 if (!list_empty(&pending
))
1370 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1372 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1373 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1374 if (sort
[i
] == cur_sort
)
1375 cur_dapm
->seq_notifier(cur_dapm
,
1380 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1382 struct snd_soc_dapm_update
*update
= dapm
->update
;
1383 struct snd_soc_dapm_widget
*w
;
1392 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1393 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1395 pr_err("%s DAPM pre-event failed: %d\n",
1399 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1402 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1405 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1406 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1408 pr_err("%s DAPM post-event failed: %d\n",
1413 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1414 * they're changing state.
1416 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1418 struct snd_soc_dapm_context
*d
= data
;
1421 /* If we're off and we're not supposed to be go into STANDBY */
1422 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1423 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1425 pm_runtime_get_sync(d
->dev
);
1427 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1430 "Failed to turn on bias: %d\n", ret
);
1433 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1434 if (d
->bias_level
!= d
->target_bias_level
) {
1435 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1438 "Failed to prepare bias: %d\n", ret
);
1442 /* Async callback run prior to DAPM sequences - brings to their final
1445 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1447 struct snd_soc_dapm_context
*d
= data
;
1450 /* If we just powered the last thing off drop to standby bias */
1451 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1452 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1453 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1454 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1456 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1460 /* If we're in standby and can support bias off then do that */
1461 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1462 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1463 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1465 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1468 pm_runtime_put(d
->dev
);
1471 /* If we just powered up then move to active bias */
1472 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1473 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1474 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1476 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1481 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1482 bool power
, bool connect
)
1484 /* If a connection is being made or broken then that update
1485 * will have marked the peer dirty, otherwise the widgets are
1486 * not connected and this update has no impact. */
1490 /* If the peer is already in the state we're moving to then we
1491 * won't have an impact on it. */
1492 if (power
!= peer
->power
)
1493 dapm_mark_dirty(peer
, "peer state change");
1496 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1497 struct list_head
*up_list
,
1498 struct list_head
*down_list
)
1500 struct snd_soc_dapm_path
*path
;
1502 if (w
->power
== power
)
1505 trace_snd_soc_dapm_widget_power(w
, power
);
1507 /* If we changed our power state perhaps our neigbours changed
1510 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1512 dapm_widget_set_peer_power(path
->source
, power
,
1517 case snd_soc_dapm_supply
:
1518 case snd_soc_dapm_regulator_supply
:
1519 case snd_soc_dapm_clock_supply
:
1520 /* Supplies can't affect their outputs, only their inputs */
1523 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1525 dapm_widget_set_peer_power(path
->sink
, power
,
1533 dapm_seq_insert(w
, up_list
, true);
1535 dapm_seq_insert(w
, down_list
, false);
1540 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1541 struct list_head
*up_list
,
1542 struct list_head
*down_list
)
1547 case snd_soc_dapm_pre
:
1548 dapm_seq_insert(w
, down_list
, false);
1550 case snd_soc_dapm_post
:
1551 dapm_seq_insert(w
, up_list
, true);
1555 power
= dapm_widget_power_check(w
);
1557 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1563 * Scan each dapm widget for complete audio path.
1564 * A complete path is a route that has valid endpoints i.e.:-
1566 * o DAC to output pin.
1567 * o Input Pin to ADC.
1568 * o Input pin to Output pin (bypass, sidetone)
1569 * o DAC to ADC (loopback).
1571 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1573 struct snd_soc_card
*card
= dapm
->card
;
1574 struct snd_soc_dapm_widget
*w
;
1575 struct snd_soc_dapm_context
*d
;
1577 LIST_HEAD(down_list
);
1578 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1579 enum snd_soc_bias_level bias
;
1581 trace_snd_soc_dapm_start(card
);
1583 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1584 if (d
->idle_bias_off
)
1585 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1587 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1592 /* Check which widgets we need to power and store them in
1593 * lists indicating if they should be powered up or down. We
1594 * only check widgets that have been flagged as dirty but note
1595 * that new widgets may be added to the dirty list while we
1598 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1599 dapm_power_one_widget(w
, &up_list
, &down_list
);
1602 list_for_each_entry(w
, &card
->widgets
, list
) {
1604 case snd_soc_dapm_pre
:
1605 case snd_soc_dapm_post
:
1606 /* These widgets always need to be powered */
1609 list_del_init(&w
->dirty
);
1616 /* Supplies and micbiases only bring the
1617 * context up to STANDBY as unless something
1618 * else is active and passing audio they
1619 * generally don't require full power. Signal
1620 * generators are virtual pins and have no
1621 * power impact themselves.
1624 case snd_soc_dapm_siggen
:
1626 case snd_soc_dapm_supply
:
1627 case snd_soc_dapm_regulator_supply
:
1628 case snd_soc_dapm_clock_supply
:
1629 case snd_soc_dapm_micbias
:
1630 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1631 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1634 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1641 /* Force all contexts in the card to the same bias state if
1642 * they're not ground referenced.
1644 bias
= SND_SOC_BIAS_OFF
;
1645 list_for_each_entry(d
, &card
->dapm_list
, list
)
1646 if (d
->target_bias_level
> bias
)
1647 bias
= d
->target_bias_level
;
1648 list_for_each_entry(d
, &card
->dapm_list
, list
)
1649 if (!d
->idle_bias_off
)
1650 d
->target_bias_level
= bias
;
1652 trace_snd_soc_dapm_walk_done(card
);
1654 /* Run all the bias changes in parallel */
1655 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1656 async_schedule_domain(dapm_pre_sequence_async
, d
,
1658 async_synchronize_full_domain(&async_domain
);
1660 /* Power down widgets first; try to avoid amplifying pops. */
1661 dapm_seq_run(dapm
, &down_list
, event
, false);
1663 dapm_widget_update(dapm
);
1666 dapm_seq_run(dapm
, &up_list
, event
, true);
1668 /* Run all the bias changes in parallel */
1669 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1670 async_schedule_domain(dapm_post_sequence_async
, d
,
1672 async_synchronize_full_domain(&async_domain
);
1674 /* do we need to notify any clients that DAPM event is complete */
1675 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1676 if (d
->stream_event
)
1677 d
->stream_event(d
, event
);
1680 pop_dbg(dapm
->dev
, card
->pop_time
,
1681 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1682 pop_wait(card
->pop_time
);
1684 trace_snd_soc_dapm_done(card
);
1689 #ifdef CONFIG_DEBUG_FS
1690 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1691 char __user
*user_buf
,
1692 size_t count
, loff_t
*ppos
)
1694 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1698 struct snd_soc_dapm_path
*p
= NULL
;
1700 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1704 in
= is_connected_input_ep(w
, NULL
);
1705 dapm_clear_walk(w
->dapm
);
1706 out
= is_connected_output_ep(w
, NULL
);
1707 dapm_clear_walk(w
->dapm
);
1709 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1710 w
->name
, w
->power
? "On" : "Off",
1711 w
->force
? " (forced)" : "", in
, out
);
1714 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1715 " - R%d(0x%x) bit %d",
1716 w
->reg
, w
->reg
, w
->shift
);
1718 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1721 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1723 w
->active
? "active" : "inactive");
1725 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1726 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1730 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1731 " in \"%s\" \"%s\"\n",
1732 p
->name
? p
->name
: "static",
1735 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1736 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1740 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1741 " out \"%s\" \"%s\"\n",
1742 p
->name
? p
->name
: "static",
1746 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1752 static const struct file_operations dapm_widget_power_fops
= {
1753 .open
= simple_open
,
1754 .read
= dapm_widget_power_read_file
,
1755 .llseek
= default_llseek
,
1758 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1759 size_t count
, loff_t
*ppos
)
1761 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1764 switch (dapm
->bias_level
) {
1765 case SND_SOC_BIAS_ON
:
1768 case SND_SOC_BIAS_PREPARE
:
1769 level
= "Prepare\n";
1771 case SND_SOC_BIAS_STANDBY
:
1772 level
= "Standby\n";
1774 case SND_SOC_BIAS_OFF
:
1779 level
= "Unknown\n";
1783 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1787 static const struct file_operations dapm_bias_fops
= {
1788 .open
= simple_open
,
1789 .read
= dapm_bias_read_file
,
1790 .llseek
= default_llseek
,
1793 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1794 struct dentry
*parent
)
1798 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1800 if (!dapm
->debugfs_dapm
) {
1802 "Failed to create DAPM debugfs directory\n");
1806 d
= debugfs_create_file("bias_level", 0444,
1807 dapm
->debugfs_dapm
, dapm
,
1811 "ASoC: Failed to create bias level debugfs file\n");
1814 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1816 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1819 if (!dapm
->debugfs_dapm
|| !w
->name
)
1822 d
= debugfs_create_file(w
->name
, 0444,
1823 dapm
->debugfs_dapm
, w
,
1824 &dapm_widget_power_fops
);
1826 dev_warn(w
->dapm
->dev
,
1827 "ASoC: Failed to create %s debugfs file\n",
1831 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1833 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1837 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1838 struct dentry
*parent
)
1842 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1846 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1852 /* test and update the power status of a mux widget */
1853 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1854 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1856 struct snd_soc_dapm_path
*path
;
1859 if (widget
->id
!= snd_soc_dapm_mux
&&
1860 widget
->id
!= snd_soc_dapm_virt_mux
&&
1861 widget
->id
!= snd_soc_dapm_value_mux
)
1864 /* find dapm widget path assoc with kcontrol */
1865 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1866 if (path
->kcontrol
!= kcontrol
)
1869 if (!path
->name
|| !e
->texts
[mux
])
1873 /* we now need to match the string in the enum to the path */
1874 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
1875 path
->connect
= 1; /* new connection */
1876 dapm_mark_dirty(path
->source
, "mux connection");
1879 dapm_mark_dirty(path
->source
,
1880 "mux disconnection");
1881 path
->connect
= 0; /* old connection must be powered down */
1886 dapm_mark_dirty(widget
, "mux change");
1887 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1893 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1894 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1896 struct snd_soc_card
*card
= widget
->dapm
->card
;
1899 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1900 ret
= soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
1901 mutex_unlock(&card
->dapm_mutex
);
1903 soc_dpcm_runtime_update(widget
);
1906 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
1908 /* test and update the power status of a mixer or switch widget */
1909 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1910 struct snd_kcontrol
*kcontrol
, int connect
)
1912 struct snd_soc_dapm_path
*path
;
1915 if (widget
->id
!= snd_soc_dapm_mixer
&&
1916 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1917 widget
->id
!= snd_soc_dapm_switch
)
1920 /* find dapm widget path assoc with kcontrol */
1921 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1922 if (path
->kcontrol
!= kcontrol
)
1925 /* found, now check type */
1927 path
->connect
= connect
;
1928 dapm_mark_dirty(path
->source
, "mixer connection");
1932 dapm_mark_dirty(widget
, "mixer update");
1933 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1939 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1940 struct snd_kcontrol
*kcontrol
, int connect
)
1942 struct snd_soc_card
*card
= widget
->dapm
->card
;
1945 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1946 ret
= soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
1947 mutex_unlock(&card
->dapm_mutex
);
1949 soc_dpcm_runtime_update(widget
);
1952 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
1954 /* show dapm widget status in sys fs */
1955 static ssize_t
dapm_widget_show(struct device
*dev
,
1956 struct device_attribute
*attr
, char *buf
)
1958 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
1959 struct snd_soc_codec
*codec
=rtd
->codec
;
1960 struct snd_soc_dapm_widget
*w
;
1962 char *state
= "not set";
1964 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1965 if (w
->dapm
!= &codec
->dapm
)
1968 /* only display widgets that burnm power */
1970 case snd_soc_dapm_hp
:
1971 case snd_soc_dapm_mic
:
1972 case snd_soc_dapm_spk
:
1973 case snd_soc_dapm_line
:
1974 case snd_soc_dapm_micbias
:
1975 case snd_soc_dapm_dac
:
1976 case snd_soc_dapm_adc
:
1977 case snd_soc_dapm_pga
:
1978 case snd_soc_dapm_out_drv
:
1979 case snd_soc_dapm_mixer
:
1980 case snd_soc_dapm_mixer_named_ctl
:
1981 case snd_soc_dapm_supply
:
1982 case snd_soc_dapm_regulator_supply
:
1983 case snd_soc_dapm_clock_supply
:
1985 count
+= sprintf(buf
+ count
, "%s: %s\n",
1986 w
->name
, w
->power
? "On":"Off");
1993 switch (codec
->dapm
.bias_level
) {
1994 case SND_SOC_BIAS_ON
:
1997 case SND_SOC_BIAS_PREPARE
:
2000 case SND_SOC_BIAS_STANDBY
:
2003 case SND_SOC_BIAS_OFF
:
2007 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2012 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2014 int snd_soc_dapm_sys_add(struct device
*dev
)
2016 return device_create_file(dev
, &dev_attr_dapm_widget
);
2019 static void snd_soc_dapm_sys_remove(struct device
*dev
)
2021 device_remove_file(dev
, &dev_attr_dapm_widget
);
2024 /* free all dapm widgets and resources */
2025 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2027 struct snd_soc_dapm_widget
*w
, *next_w
;
2028 struct snd_soc_dapm_path
*p
, *next_p
;
2030 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2031 if (w
->dapm
!= dapm
)
2035 * remove source and sink paths associated to this widget.
2036 * While removing the path, remove reference to it from both
2037 * source and sink widgets so that path is removed only once.
2039 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
2040 list_del(&p
->list_sink
);
2041 list_del(&p
->list_source
);
2043 kfree(p
->long_name
);
2046 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
2047 list_del(&p
->list_sink
);
2048 list_del(&p
->list_source
);
2050 kfree(p
->long_name
);
2053 kfree(w
->kcontrols
);
2059 static struct snd_soc_dapm_widget
*dapm_find_widget(
2060 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2061 bool search_other_contexts
)
2063 struct snd_soc_dapm_widget
*w
;
2064 struct snd_soc_dapm_widget
*fallback
= NULL
;
2066 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2067 if (!strcmp(w
->name
, pin
)) {
2068 if (w
->dapm
== dapm
)
2075 if (search_other_contexts
)
2081 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2082 const char *pin
, int status
)
2084 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2087 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2091 if (w
->connected
!= status
)
2092 dapm_mark_dirty(w
, "pin configuration");
2094 w
->connected
= status
;
2102 * snd_soc_dapm_sync - scan and power dapm paths
2103 * @dapm: DAPM context
2105 * Walks all dapm audio paths and powers widgets according to their
2106 * stream or path usage.
2108 * Returns 0 for success.
2110 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2115 * Suppress early reports (eg, jacks syncing their state) to avoid
2116 * silly DAPM runs during card startup.
2118 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2121 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2122 ret
= dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2123 mutex_unlock(&dapm
->card
->dapm_mutex
);
2126 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2128 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2129 const struct snd_soc_dapm_route
*route
)
2131 struct snd_soc_dapm_path
*path
;
2132 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2133 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2135 const char *control
= route
->control
;
2137 char prefixed_sink
[80];
2138 char prefixed_source
[80];
2141 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2142 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2143 dapm
->codec
->name_prefix
, route
->sink
);
2144 sink
= prefixed_sink
;
2145 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2146 dapm
->codec
->name_prefix
, route
->source
);
2147 source
= prefixed_source
;
2150 source
= route
->source
;
2154 * find src and dest widgets over all widgets but favor a widget from
2155 * current DAPM context
2157 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2158 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2160 if (w
->dapm
== dapm
)
2164 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2166 if (w
->dapm
== dapm
)
2170 /* use widget from another DAPM context if not found from this */
2176 if (wsource
== NULL
|| wsink
== NULL
)
2179 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2183 path
->source
= wsource
;
2185 path
->connected
= route
->connected
;
2186 INIT_LIST_HEAD(&path
->list
);
2187 INIT_LIST_HEAD(&path
->list_source
);
2188 INIT_LIST_HEAD(&path
->list_sink
);
2190 /* check for external widgets */
2191 if (wsink
->id
== snd_soc_dapm_input
) {
2192 if (wsource
->id
== snd_soc_dapm_micbias
||
2193 wsource
->id
== snd_soc_dapm_mic
||
2194 wsource
->id
== snd_soc_dapm_line
||
2195 wsource
->id
== snd_soc_dapm_output
)
2198 if (wsource
->id
== snd_soc_dapm_output
) {
2199 if (wsink
->id
== snd_soc_dapm_spk
||
2200 wsink
->id
== snd_soc_dapm_hp
||
2201 wsink
->id
== snd_soc_dapm_line
||
2202 wsink
->id
== snd_soc_dapm_input
)
2206 /* connect static paths */
2207 if (control
== NULL
) {
2208 list_add(&path
->list
, &dapm
->card
->paths
);
2209 list_add(&path
->list_sink
, &wsink
->sources
);
2210 list_add(&path
->list_source
, &wsource
->sinks
);
2215 /* connect dynamic paths */
2216 switch (wsink
->id
) {
2217 case snd_soc_dapm_adc
:
2218 case snd_soc_dapm_dac
:
2219 case snd_soc_dapm_pga
:
2220 case snd_soc_dapm_out_drv
:
2221 case snd_soc_dapm_input
:
2222 case snd_soc_dapm_output
:
2223 case snd_soc_dapm_siggen
:
2224 case snd_soc_dapm_micbias
:
2225 case snd_soc_dapm_vmid
:
2226 case snd_soc_dapm_pre
:
2227 case snd_soc_dapm_post
:
2228 case snd_soc_dapm_supply
:
2229 case snd_soc_dapm_regulator_supply
:
2230 case snd_soc_dapm_clock_supply
:
2231 case snd_soc_dapm_aif_in
:
2232 case snd_soc_dapm_aif_out
:
2233 case snd_soc_dapm_dai
:
2234 case snd_soc_dapm_dai_link
:
2235 list_add(&path
->list
, &dapm
->card
->paths
);
2236 list_add(&path
->list_sink
, &wsink
->sources
);
2237 list_add(&path
->list_source
, &wsource
->sinks
);
2240 case snd_soc_dapm_mux
:
2241 case snd_soc_dapm_virt_mux
:
2242 case snd_soc_dapm_value_mux
:
2243 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2244 &wsink
->kcontrol_news
[0]);
2248 case snd_soc_dapm_switch
:
2249 case snd_soc_dapm_mixer
:
2250 case snd_soc_dapm_mixer_named_ctl
:
2251 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2255 case snd_soc_dapm_hp
:
2256 case snd_soc_dapm_mic
:
2257 case snd_soc_dapm_line
:
2258 case snd_soc_dapm_spk
:
2259 list_add(&path
->list
, &dapm
->card
->paths
);
2260 list_add(&path
->list_sink
, &wsink
->sources
);
2261 list_add(&path
->list_source
, &wsource
->sinks
);
2266 dapm_mark_dirty(wsource
, "Route added");
2267 dapm_mark_dirty(wsink
, "Route added");
2272 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
2273 source
, control
, sink
);
2278 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2279 const struct snd_soc_dapm_route
*route
)
2281 struct snd_soc_dapm_path
*path
, *p
;
2284 char prefixed_sink
[80];
2285 char prefixed_source
[80];
2287 if (route
->control
) {
2289 "Removal of routes with controls not supported\n");
2293 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2294 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2295 dapm
->codec
->name_prefix
, route
->sink
);
2296 sink
= prefixed_sink
;
2297 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2298 dapm
->codec
->name_prefix
, route
->source
);
2299 source
= prefixed_source
;
2302 source
= route
->source
;
2306 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2307 if (strcmp(p
->source
->name
, source
) != 0)
2309 if (strcmp(p
->sink
->name
, sink
) != 0)
2316 dapm_mark_dirty(path
->source
, "Route removed");
2317 dapm_mark_dirty(path
->sink
, "Route removed");
2319 list_del(&path
->list
);
2320 list_del(&path
->list_sink
);
2321 list_del(&path
->list_source
);
2324 dev_warn(dapm
->dev
, "Route %s->%s does not exist\n",
2332 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2333 * @dapm: DAPM context
2334 * @route: audio routes
2335 * @num: number of routes
2337 * Connects 2 dapm widgets together via a named audio path. The sink is
2338 * the widget receiving the audio signal, whilst the source is the sender
2339 * of the audio signal.
2341 * Returns 0 for success else error. On error all resources can be freed
2342 * with a call to snd_soc_card_free().
2344 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2345 const struct snd_soc_dapm_route
*route
, int num
)
2349 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2350 for (i
= 0; i
< num
; i
++) {
2351 r
= snd_soc_dapm_add_route(dapm
, route
);
2353 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
2354 route
->source
, route
->sink
);
2359 mutex_unlock(&dapm
->card
->dapm_mutex
);
2363 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2366 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2367 * @dapm: DAPM context
2368 * @route: audio routes
2369 * @num: number of routes
2371 * Removes routes from the DAPM context.
2373 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2374 const struct snd_soc_dapm_route
*route
, int num
)
2378 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2379 for (i
= 0; i
< num
; i
++) {
2380 snd_soc_dapm_del_route(dapm
, route
);
2383 mutex_unlock(&dapm
->card
->dapm_mutex
);
2387 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2389 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2390 const struct snd_soc_dapm_route
*route
)
2392 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2395 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2398 struct snd_soc_dapm_path
*path
;
2402 dev_err(dapm
->dev
, "Unable to find source %s for weak route\n",
2408 dev_err(dapm
->dev
, "Unable to find sink %s for weak route\n",
2413 if (route
->control
|| route
->connected
)
2414 dev_warn(dapm
->dev
, "Ignoring control for weak route %s->%s\n",
2415 route
->source
, route
->sink
);
2417 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2418 if (path
->sink
== sink
) {
2425 dev_err(dapm
->dev
, "No path found for weak route %s->%s\n",
2426 route
->source
, route
->sink
);
2428 dev_warn(dapm
->dev
, "%d paths found for weak route %s->%s\n",
2429 count
, route
->source
, route
->sink
);
2435 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2436 * @dapm: DAPM context
2437 * @route: audio routes
2438 * @num: number of routes
2440 * Mark existing routes matching those specified in the passed array
2441 * as being weak, meaning that they are ignored for the purpose of
2442 * power decisions. The main intended use case is for sidetone paths
2443 * which couple audio between other independent paths if they are both
2444 * active in order to make the combination work better at the user
2445 * level but which aren't intended to be "used".
2447 * Note that CODEC drivers should not use this as sidetone type paths
2448 * can frequently also be used as bypass paths.
2450 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2451 const struct snd_soc_dapm_route
*route
, int num
)
2456 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2457 for (i
= 0; i
< num
; i
++) {
2458 err
= snd_soc_dapm_weak_route(dapm
, route
);
2463 mutex_unlock(&dapm
->card
->dapm_mutex
);
2467 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2470 * snd_soc_dapm_new_widgets - add new dapm widgets
2471 * @dapm: DAPM context
2473 * Checks the codec for any new dapm widgets and creates them if found.
2475 * Returns 0 for success.
2477 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
2479 struct snd_soc_dapm_widget
*w
;
2482 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2484 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2489 if (w
->num_kcontrols
) {
2490 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2491 sizeof(struct snd_kcontrol
*),
2493 if (!w
->kcontrols
) {
2494 mutex_unlock(&dapm
->card
->dapm_mutex
);
2500 case snd_soc_dapm_switch
:
2501 case snd_soc_dapm_mixer
:
2502 case snd_soc_dapm_mixer_named_ctl
:
2505 case snd_soc_dapm_mux
:
2506 case snd_soc_dapm_virt_mux
:
2507 case snd_soc_dapm_value_mux
:
2510 case snd_soc_dapm_pga
:
2511 case snd_soc_dapm_out_drv
:
2518 /* Read the initial power state from the device */
2520 val
= soc_widget_read(w
, w
->reg
);
2521 val
&= 1 << w
->shift
;
2531 dapm_mark_dirty(w
, "new widget");
2532 dapm_debugfs_add_widget(w
);
2535 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2536 mutex_unlock(&dapm
->card
->dapm_mutex
);
2539 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2542 * snd_soc_dapm_get_volsw - dapm mixer get callback
2543 * @kcontrol: mixer control
2544 * @ucontrol: control element information
2546 * Callback to get the value of a dapm mixer control.
2548 * Returns 0 for success.
2550 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2551 struct snd_ctl_elem_value
*ucontrol
)
2553 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2554 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2555 struct soc_mixer_control
*mc
=
2556 (struct soc_mixer_control
*)kcontrol
->private_value
;
2557 unsigned int reg
= mc
->reg
;
2558 unsigned int shift
= mc
->shift
;
2560 unsigned int mask
= (1 << fls(max
)) - 1;
2561 unsigned int invert
= mc
->invert
;
2563 if (snd_soc_volsw_is_stereo(mc
))
2564 dev_warn(widget
->dapm
->dev
,
2565 "Control '%s' is stereo, which is not supported\n",
2568 ucontrol
->value
.integer
.value
[0] =
2569 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2571 ucontrol
->value
.integer
.value
[0] =
2572 max
- ucontrol
->value
.integer
.value
[0];
2576 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2579 * snd_soc_dapm_put_volsw - dapm mixer set callback
2580 * @kcontrol: mixer control
2581 * @ucontrol: control element information
2583 * Callback to set the value of a dapm mixer control.
2585 * Returns 0 for success.
2587 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2588 struct snd_ctl_elem_value
*ucontrol
)
2590 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2591 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2592 struct snd_soc_codec
*codec
= widget
->codec
;
2593 struct snd_soc_card
*card
= codec
->card
;
2594 struct soc_mixer_control
*mc
=
2595 (struct soc_mixer_control
*)kcontrol
->private_value
;
2596 unsigned int reg
= mc
->reg
;
2597 unsigned int shift
= mc
->shift
;
2599 unsigned int mask
= (1 << fls(max
)) - 1;
2600 unsigned int invert
= mc
->invert
;
2602 int connect
, change
;
2603 struct snd_soc_dapm_update update
;
2606 if (snd_soc_volsw_is_stereo(mc
))
2607 dev_warn(widget
->dapm
->dev
,
2608 "Control '%s' is stereo, which is not supported\n",
2611 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2616 mask
= mask
<< shift
;
2619 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2621 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2623 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2624 widget
= wlist
->widgets
[wi
];
2626 widget
->value
= val
;
2628 update
.kcontrol
= kcontrol
;
2629 update
.widget
= widget
;
2633 widget
->dapm
->update
= &update
;
2635 soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2637 widget
->dapm
->update
= NULL
;
2641 mutex_unlock(&card
->dapm_mutex
);
2644 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2647 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2648 * @kcontrol: mixer control
2649 * @ucontrol: control element information
2651 * Callback to get the value of a dapm enumerated double mixer control.
2653 * Returns 0 for success.
2655 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2656 struct snd_ctl_elem_value
*ucontrol
)
2658 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2659 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2660 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2661 unsigned int val
, bitmask
;
2663 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2665 val
= snd_soc_read(widget
->codec
, e
->reg
);
2666 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2667 if (e
->shift_l
!= e
->shift_r
)
2668 ucontrol
->value
.enumerated
.item
[1] =
2669 (val
>> e
->shift_r
) & (bitmask
- 1);
2673 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2676 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2677 * @kcontrol: mixer control
2678 * @ucontrol: control element information
2680 * Callback to set the value of a dapm enumerated double mixer control.
2682 * Returns 0 for success.
2684 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2685 struct snd_ctl_elem_value
*ucontrol
)
2687 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2688 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2689 struct snd_soc_codec
*codec
= widget
->codec
;
2690 struct snd_soc_card
*card
= codec
->card
;
2691 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2692 unsigned int val
, mux
, change
;
2693 unsigned int mask
, bitmask
;
2694 struct snd_soc_dapm_update update
;
2697 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2699 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2701 mux
= ucontrol
->value
.enumerated
.item
[0];
2702 val
= mux
<< e
->shift_l
;
2703 mask
= (bitmask
- 1) << e
->shift_l
;
2704 if (e
->shift_l
!= e
->shift_r
) {
2705 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2707 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2708 mask
|= (bitmask
- 1) << e
->shift_r
;
2711 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2713 change
= snd_soc_test_bits(widget
->codec
, e
->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
;
2722 update
.reg
= e
->reg
;
2725 widget
->dapm
->update
= &update
;
2727 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2729 widget
->dapm
->update
= NULL
;
2733 mutex_unlock(&card
->dapm_mutex
);
2736 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2739 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2740 * @kcontrol: mixer control
2741 * @ucontrol: control element information
2743 * Returns 0 for success.
2745 int snd_soc_dapm_get_enum_virt(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];
2751 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2755 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2758 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2759 * @kcontrol: mixer control
2760 * @ucontrol: control element information
2762 * Returns 0 for success.
2764 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2765 struct snd_ctl_elem_value
*ucontrol
)
2767 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2768 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2769 struct snd_soc_codec
*codec
= widget
->codec
;
2770 struct snd_soc_card
*card
= codec
->card
;
2771 struct soc_enum
*e
=
2772 (struct soc_enum
*)kcontrol
->private_value
;
2777 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2780 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2782 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2784 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2785 widget
= wlist
->widgets
[wi
];
2787 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2789 soc_dapm_mux_update_power(widget
, kcontrol
, widget
->value
, e
);
2793 mutex_unlock(&card
->dapm_mutex
);
2796 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2799 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2801 * @kcontrol: mixer control
2802 * @ucontrol: control element information
2804 * Callback to get the value of a dapm semi enumerated double mixer control.
2806 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2807 * used for handling bitfield coded enumeration for example.
2809 * Returns 0 for success.
2811 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2812 struct snd_ctl_elem_value
*ucontrol
)
2814 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2815 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2816 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2817 unsigned int reg_val
, val
, mux
;
2819 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2820 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2821 for (mux
= 0; mux
< e
->max
; mux
++) {
2822 if (val
== e
->values
[mux
])
2825 ucontrol
->value
.enumerated
.item
[0] = mux
;
2826 if (e
->shift_l
!= e
->shift_r
) {
2827 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2828 for (mux
= 0; mux
< e
->max
; mux
++) {
2829 if (val
== e
->values
[mux
])
2832 ucontrol
->value
.enumerated
.item
[1] = mux
;
2837 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2840 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2842 * @kcontrol: mixer control
2843 * @ucontrol: control element information
2845 * Callback to set the value of a dapm semi enumerated double mixer control.
2847 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2848 * used for handling bitfield coded enumeration for example.
2850 * Returns 0 for success.
2852 int snd_soc_dapm_put_value_enum_double(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
= (struct soc_enum
*)kcontrol
->private_value
;
2860 unsigned int val
, mux
, change
;
2862 struct snd_soc_dapm_update update
;
2865 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2867 mux
= ucontrol
->value
.enumerated
.item
[0];
2868 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2869 mask
= e
->mask
<< e
->shift_l
;
2870 if (e
->shift_l
!= e
->shift_r
) {
2871 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2873 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2874 mask
|= e
->mask
<< e
->shift_r
;
2877 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2879 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2881 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2882 widget
= wlist
->widgets
[wi
];
2884 widget
->value
= val
;
2886 update
.kcontrol
= kcontrol
;
2887 update
.widget
= widget
;
2888 update
.reg
= e
->reg
;
2891 widget
->dapm
->update
= &update
;
2893 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2895 widget
->dapm
->update
= NULL
;
2899 mutex_unlock(&card
->dapm_mutex
);
2902 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2905 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2907 * @kcontrol: mixer control
2908 * @uinfo: control element information
2910 * Callback to provide information about a pin switch control.
2912 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2913 struct snd_ctl_elem_info
*uinfo
)
2915 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2917 uinfo
->value
.integer
.min
= 0;
2918 uinfo
->value
.integer
.max
= 1;
2922 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2925 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2927 * @kcontrol: mixer control
2930 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2931 struct snd_ctl_elem_value
*ucontrol
)
2933 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2934 const char *pin
= (const char *)kcontrol
->private_value
;
2936 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2938 ucontrol
->value
.integer
.value
[0] =
2939 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
2941 mutex_unlock(&card
->dapm_mutex
);
2945 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2948 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2950 * @kcontrol: mixer control
2953 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2954 struct snd_ctl_elem_value
*ucontrol
)
2956 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2957 const char *pin
= (const char *)kcontrol
->private_value
;
2959 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2961 if (ucontrol
->value
.integer
.value
[0])
2962 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
2964 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
2966 mutex_unlock(&card
->dapm_mutex
);
2968 snd_soc_dapm_sync(&card
->dapm
);
2971 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2973 static struct snd_soc_dapm_widget
*
2974 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2975 const struct snd_soc_dapm_widget
*widget
)
2977 struct snd_soc_dapm_widget
*w
;
2981 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2985 case snd_soc_dapm_regulator_supply
:
2986 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
2987 if (IS_ERR(w
->regulator
)) {
2988 ret
= PTR_ERR(w
->regulator
);
2989 dev_err(dapm
->dev
, "Failed to request %s: %d\n",
2994 case snd_soc_dapm_clock_supply
:
2995 #ifdef CONFIG_CLKDEV_LOOKUP
2996 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
2997 if (IS_ERR(w
->clk
)) {
2998 ret
= PTR_ERR(w
->clk
);
2999 dev_err(dapm
->dev
, "Failed to request %s: %d\n",
3011 name_len
= strlen(widget
->name
) + 1;
3012 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3013 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
3014 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
3015 if (w
->name
== NULL
) {
3019 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3020 snprintf((char *)w
->name
, name_len
, "%s %s",
3021 dapm
->codec
->name_prefix
, widget
->name
);
3023 snprintf((char *)w
->name
, name_len
, "%s", widget
->name
);
3026 case snd_soc_dapm_switch
:
3027 case snd_soc_dapm_mixer
:
3028 case snd_soc_dapm_mixer_named_ctl
:
3029 w
->power_check
= dapm_generic_check_power
;
3031 case snd_soc_dapm_mux
:
3032 case snd_soc_dapm_virt_mux
:
3033 case snd_soc_dapm_value_mux
:
3034 w
->power_check
= dapm_generic_check_power
;
3036 case snd_soc_dapm_adc
:
3037 case snd_soc_dapm_aif_out
:
3038 w
->power_check
= dapm_adc_check_power
;
3040 case snd_soc_dapm_dac
:
3041 case snd_soc_dapm_aif_in
:
3042 w
->power_check
= dapm_dac_check_power
;
3044 case snd_soc_dapm_pga
:
3045 case snd_soc_dapm_out_drv
:
3046 case snd_soc_dapm_input
:
3047 case snd_soc_dapm_output
:
3048 case snd_soc_dapm_micbias
:
3049 case snd_soc_dapm_spk
:
3050 case snd_soc_dapm_hp
:
3051 case snd_soc_dapm_mic
:
3052 case snd_soc_dapm_line
:
3053 case snd_soc_dapm_dai_link
:
3054 w
->power_check
= dapm_generic_check_power
;
3056 case snd_soc_dapm_supply
:
3057 case snd_soc_dapm_regulator_supply
:
3058 case snd_soc_dapm_clock_supply
:
3059 w
->power_check
= dapm_supply_check_power
;
3061 case snd_soc_dapm_dai
:
3062 w
->power_check
= dapm_dai_check_power
;
3065 w
->power_check
= dapm_always_on_check_power
;
3071 w
->codec
= dapm
->codec
;
3072 w
->platform
= dapm
->platform
;
3073 INIT_LIST_HEAD(&w
->sources
);
3074 INIT_LIST_HEAD(&w
->sinks
);
3075 INIT_LIST_HEAD(&w
->list
);
3076 INIT_LIST_HEAD(&w
->dirty
);
3077 list_add(&w
->list
, &dapm
->card
->widgets
);
3079 /* machine layer set ups unconnected pins and insertions */
3085 * snd_soc_dapm_new_controls - create new dapm controls
3086 * @dapm: DAPM context
3087 * @widget: widget array
3088 * @num: number of widgets
3090 * Creates new DAPM controls based upon the templates.
3092 * Returns 0 for success else error.
3094 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3095 const struct snd_soc_dapm_widget
*widget
,
3098 struct snd_soc_dapm_widget
*w
;
3102 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3103 for (i
= 0; i
< num
; i
++) {
3104 w
= snd_soc_dapm_new_control(dapm
, widget
);
3107 "ASoC: Failed to create DAPM control %s\n",
3114 mutex_unlock(&dapm
->card
->dapm_mutex
);
3117 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3119 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3120 struct snd_kcontrol
*kcontrol
, int event
)
3122 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3123 struct snd_soc_dai
*source
, *sink
;
3124 const struct snd_soc_pcm_stream
*config
= w
->params
;
3125 struct snd_pcm_substream substream
;
3126 struct snd_pcm_hw_params
*params
= NULL
;
3131 BUG_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
));
3133 /* We only support a single source and sink, pick the first */
3134 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3136 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3139 BUG_ON(!source_p
|| !sink_p
);
3140 BUG_ON(!sink_p
->source
|| !source_p
->sink
);
3141 BUG_ON(!source_p
->source
|| !sink_p
->sink
);
3143 source
= source_p
->source
->priv
;
3144 sink
= sink_p
->sink
->priv
;
3146 /* Be a little careful as we don't want to overflow the mask array */
3147 if (config
->formats
) {
3148 fmt
= ffs(config
->formats
) - 1;
3150 dev_warn(w
->dapm
->dev
, "Invalid format %llx specified\n",
3155 /* Currently very limited parameter selection */
3156 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3161 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3163 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3165 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3168 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3169 = config
->channels_min
;
3170 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3171 = config
->channels_max
;
3173 memset(&substream
, 0, sizeof(substream
));
3176 case SND_SOC_DAPM_PRE_PMU
:
3177 if (source
->driver
->ops
&& source
->driver
->ops
->hw_params
) {
3178 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3179 ret
= source
->driver
->ops
->hw_params(&substream
,
3182 dev_err(source
->dev
,
3183 "hw_params() failed: %d\n", ret
);
3188 if (sink
->driver
->ops
&& sink
->driver
->ops
->hw_params
) {
3189 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3190 ret
= sink
->driver
->ops
->hw_params(&substream
, params
,
3194 "hw_params() failed: %d\n", ret
);
3200 case SND_SOC_DAPM_POST_PMU
:
3201 ret
= snd_soc_dai_digital_mute(sink
, 0);
3202 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3203 dev_warn(sink
->dev
, "Failed to unmute: %d\n", ret
);
3207 case SND_SOC_DAPM_PRE_PMD
:
3208 ret
= snd_soc_dai_digital_mute(sink
, 1);
3209 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3210 dev_warn(sink
->dev
, "Failed to mute: %d\n", ret
);
3224 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3225 const struct snd_soc_pcm_stream
*params
,
3226 struct snd_soc_dapm_widget
*source
,
3227 struct snd_soc_dapm_widget
*sink
)
3229 struct snd_soc_dapm_route routes
[2];
3230 struct snd_soc_dapm_widget
template;
3231 struct snd_soc_dapm_widget
*w
;
3235 len
= strlen(source
->name
) + strlen(sink
->name
) + 2;
3236 link_name
= devm_kzalloc(card
->dev
, len
, GFP_KERNEL
);
3239 snprintf(link_name
, len
, "%s-%s", source
->name
, sink
->name
);
3241 memset(&template, 0, sizeof(template));
3242 template.reg
= SND_SOC_NOPM
;
3243 template.id
= snd_soc_dapm_dai_link
;
3244 template.name
= link_name
;
3245 template.event
= snd_soc_dai_link_event
;
3246 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3247 SND_SOC_DAPM_PRE_PMD
;
3249 dev_dbg(card
->dev
, "adding %s widget\n", link_name
);
3251 w
= snd_soc_dapm_new_control(&card
->dapm
, &template);
3253 dev_err(card
->dev
, "Failed to create %s widget\n",
3260 memset(&routes
, 0, sizeof(routes
));
3262 routes
[0].source
= source
->name
;
3263 routes
[0].sink
= link_name
;
3264 routes
[1].source
= link_name
;
3265 routes
[1].sink
= sink
->name
;
3267 return snd_soc_dapm_add_routes(&card
->dapm
, routes
,
3268 ARRAY_SIZE(routes
));
3271 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3272 struct snd_soc_dai
*dai
)
3274 struct snd_soc_dapm_widget
template;
3275 struct snd_soc_dapm_widget
*w
;
3277 WARN_ON(dapm
->dev
!= dai
->dev
);
3279 memset(&template, 0, sizeof(template));
3280 template.reg
= SND_SOC_NOPM
;
3282 if (dai
->driver
->playback
.stream_name
) {
3283 template.id
= snd_soc_dapm_dai
;
3284 template.name
= dai
->driver
->playback
.stream_name
;
3285 template.sname
= dai
->driver
->playback
.stream_name
;
3287 dev_dbg(dai
->dev
, "adding %s widget\n",
3290 w
= snd_soc_dapm_new_control(dapm
, &template);
3292 dev_err(dapm
->dev
, "Failed to create %s widget\n",
3293 dai
->driver
->playback
.stream_name
);
3297 dai
->playback_widget
= w
;
3300 if (dai
->driver
->capture
.stream_name
) {
3301 template.id
= snd_soc_dapm_dai
;
3302 template.name
= dai
->driver
->capture
.stream_name
;
3303 template.sname
= dai
->driver
->capture
.stream_name
;
3305 dev_dbg(dai
->dev
, "adding %s widget\n",
3308 w
= snd_soc_dapm_new_control(dapm
, &template);
3310 dev_err(dapm
->dev
, "Failed to create %s widget\n",
3311 dai
->driver
->capture
.stream_name
);
3315 dai
->capture_widget
= w
;
3321 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3323 struct snd_soc_dapm_widget
*dai_w
, *w
;
3324 struct snd_soc_dai
*dai
;
3325 struct snd_soc_dapm_route r
;
3327 memset(&r
, 0, sizeof(r
));
3329 /* For each DAI widget... */
3330 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3331 if (dai_w
->id
!= snd_soc_dapm_dai
)
3336 /* ...find all widgets with the same stream and link them */
3337 list_for_each_entry(w
, &card
->widgets
, list
) {
3338 if (w
->dapm
!= dai_w
->dapm
)
3341 if (w
->id
== snd_soc_dapm_dai
)
3347 if (dai
->driver
->playback
.stream_name
&&
3349 dai
->driver
->playback
.stream_name
)) {
3350 r
.source
= dai
->playback_widget
->name
;
3352 dev_dbg(dai
->dev
, "%s -> %s\n",
3355 snd_soc_dapm_add_route(w
->dapm
, &r
);
3358 if (dai
->driver
->capture
.stream_name
&&
3360 dai
->driver
->capture
.stream_name
)) {
3362 r
.sink
= dai
->capture_widget
->name
;
3363 dev_dbg(dai
->dev
, "%s -> %s\n",
3366 snd_soc_dapm_add_route(w
->dapm
, &r
);
3374 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3378 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
3379 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3380 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
3382 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3383 w_cpu
= cpu_dai
->playback_widget
;
3384 w_codec
= codec_dai
->playback_widget
;
3386 w_cpu
= cpu_dai
->capture_widget
;
3387 w_codec
= codec_dai
->capture_widget
;
3392 dapm_mark_dirty(w_cpu
, "stream event");
3395 case SND_SOC_DAPM_STREAM_START
:
3398 case SND_SOC_DAPM_STREAM_STOP
:
3401 case SND_SOC_DAPM_STREAM_SUSPEND
:
3402 case SND_SOC_DAPM_STREAM_RESUME
:
3403 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3404 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3411 dapm_mark_dirty(w_codec
, "stream event");
3414 case SND_SOC_DAPM_STREAM_START
:
3415 w_codec
->active
= 1;
3417 case SND_SOC_DAPM_STREAM_STOP
:
3418 w_codec
->active
= 0;
3420 case SND_SOC_DAPM_STREAM_SUSPEND
:
3421 case SND_SOC_DAPM_STREAM_RESUME
:
3422 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3423 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3428 dapm_power_widgets(&rtd
->card
->dapm
, event
);
3432 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3433 * @rtd: PCM runtime data
3434 * @stream: stream name
3435 * @event: stream event
3437 * Sends a stream event to the dapm core. The core then makes any
3438 * necessary widget power changes.
3440 * Returns 0 for success else error.
3442 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3445 struct snd_soc_card
*card
= rtd
->card
;
3447 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3448 soc_dapm_stream_event(rtd
, stream
, event
);
3449 mutex_unlock(&card
->dapm_mutex
);
3453 * snd_soc_dapm_enable_pin - enable pin.
3454 * @dapm: DAPM context
3457 * Enables input/output pin and its parents or children widgets iff there is
3458 * a valid audio route and active audio stream.
3459 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3460 * do any widget power switching.
3462 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3464 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3466 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3469 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3470 * @dapm: DAPM context
3473 * Enables input/output pin regardless of any other state. This is
3474 * intended for use with microphone bias supplies used in microphone
3477 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3478 * do any widget power switching.
3480 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3483 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3486 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3490 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
3493 dapm_mark_dirty(w
, "force enable");
3497 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3500 * snd_soc_dapm_disable_pin - disable pin.
3501 * @dapm: DAPM context
3504 * Disables input/output pin and its parents or children widgets.
3505 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3506 * do any widget power switching.
3508 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3511 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3513 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3516 * snd_soc_dapm_nc_pin - permanently disable pin.
3517 * @dapm: DAPM context
3520 * Marks the specified pin as being not connected, disabling it along
3521 * any parent or child widgets. At present this is identical to
3522 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3523 * additional things such as disabling controls which only affect
3524 * paths through the pin.
3526 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3527 * do any widget power switching.
3529 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3531 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3533 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3536 * snd_soc_dapm_get_pin_status - get audio pin status
3537 * @dapm: DAPM context
3538 * @pin: audio signal pin endpoint (or start point)
3540 * Get audio pin status - connected or disconnected.
3542 * Returns 1 for connected otherwise 0.
3544 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3547 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3550 return w
->connected
;
3554 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
3557 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3558 * @dapm: DAPM context
3559 * @pin: audio signal pin endpoint (or start point)
3561 * Mark the given endpoint or pin as ignoring suspend. When the
3562 * system is disabled a path between two endpoints flagged as ignoring
3563 * suspend will not be disabled. The path must already be enabled via
3564 * normal means at suspend time, it will not be turned on if it was not
3567 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
3570 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
3573 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3577 w
->ignore_suspend
= 1;
3581 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
3583 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
3584 struct snd_soc_dapm_widget
*w
)
3586 struct snd_soc_dapm_path
*p
;
3588 list_for_each_entry(p
, &card
->paths
, list
) {
3589 if ((p
->source
== w
) || (p
->sink
== w
)) {
3591 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3592 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
3593 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
3595 /* Connected to something other than the codec */
3596 if (p
->source
->dapm
!= p
->sink
->dapm
)
3599 * Loopback connection from codec external pin to
3600 * codec external pin
3602 if (p
->sink
->id
== snd_soc_dapm_input
) {
3603 switch (p
->source
->id
) {
3604 case snd_soc_dapm_output
:
3605 case snd_soc_dapm_micbias
:
3618 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3619 * @codec: The codec whose pins should be processed
3621 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3622 * which are unused. Pins are used if they are connected externally to the
3623 * codec, whether that be to some other device, or a loop-back connection to
3626 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
3628 struct snd_soc_card
*card
= codec
->card
;
3629 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3630 struct snd_soc_dapm_widget
*w
;
3632 dev_dbg(codec
->dev
, "Auto NC: DAPMs: card:%p codec:%p\n",
3633 &card
->dapm
, &codec
->dapm
);
3635 list_for_each_entry(w
, &card
->widgets
, list
) {
3636 if (w
->dapm
!= dapm
)
3639 case snd_soc_dapm_input
:
3640 case snd_soc_dapm_output
:
3641 case snd_soc_dapm_micbias
:
3642 dev_dbg(codec
->dev
, "Auto NC: Checking widget %s\n",
3644 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
3646 "... Not in map; disabling\n");
3647 snd_soc_dapm_nc_pin(dapm
, w
->name
);
3657 * snd_soc_dapm_free - free dapm resources
3658 * @dapm: DAPM context
3660 * Free all dapm widgets and resources.
3662 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
3664 snd_soc_dapm_sys_remove(dapm
->dev
);
3665 dapm_debugfs_cleanup(dapm
);
3666 dapm_free_widgets(dapm
);
3667 list_del(&dapm
->list
);
3669 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
3671 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
3673 struct snd_soc_card
*card
= dapm
->card
;
3674 struct snd_soc_dapm_widget
*w
;
3675 LIST_HEAD(down_list
);
3678 mutex_lock(&card
->dapm_mutex
);
3680 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
3681 if (w
->dapm
!= dapm
)
3684 dapm_seq_insert(w
, &down_list
, false);
3690 /* If there were no widgets to power down we're already in
3694 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
3695 snd_soc_dapm_set_bias_level(dapm
,
3696 SND_SOC_BIAS_PREPARE
);
3697 dapm_seq_run(dapm
, &down_list
, 0, false);
3698 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
3699 snd_soc_dapm_set_bias_level(dapm
,
3700 SND_SOC_BIAS_STANDBY
);
3703 mutex_unlock(&card
->dapm_mutex
);
3707 * snd_soc_dapm_shutdown - callback for system shutdown
3709 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
3711 struct snd_soc_codec
*codec
;
3713 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
3714 soc_dapm_shutdown_codec(&codec
->dapm
);
3715 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
3716 snd_soc_dapm_set_bias_level(&codec
->dapm
,
3721 /* Module information */
3722 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3723 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3724 MODULE_LICENSE("GPL");