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
, "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
, "no valid widget write method\n");
238 static inline void soc_widget_lock(struct snd_soc_dapm_widget
*w
)
240 if (w
->codec
&& !w
->codec
->using_regmap
)
241 mutex_lock(&w
->codec
->mutex
);
242 else if (w
->platform
)
243 mutex_lock(&w
->platform
->mutex
);
246 static inline void soc_widget_unlock(struct snd_soc_dapm_widget
*w
)
248 if (w
->codec
&& !w
->codec
->using_regmap
)
249 mutex_unlock(&w
->codec
->mutex
);
250 else if (w
->platform
)
251 mutex_unlock(&w
->platform
->mutex
);
254 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget
*w
,
255 unsigned short reg
, unsigned int mask
, unsigned int value
)
258 unsigned int old
, new;
261 if (w
->codec
&& w
->codec
->using_regmap
) {
262 ret
= regmap_update_bits_check(w
->codec
->control_data
,
263 reg
, mask
, value
, &change
);
268 ret
= soc_widget_read(w
, reg
);
270 soc_widget_unlock(w
);
275 new = (old
& ~mask
) | (value
& mask
);
278 ret
= soc_widget_write(w
, reg
, new);
280 soc_widget_unlock(w
);
284 soc_widget_unlock(w
);
291 * snd_soc_dapm_set_bias_level - set the bias level for the system
292 * @dapm: DAPM context
293 * @level: level to configure
295 * Configure the bias (power) levels for the SoC audio device.
297 * Returns 0 for success else error.
299 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
300 enum snd_soc_bias_level level
)
302 struct snd_soc_card
*card
= dapm
->card
;
305 trace_snd_soc_bias_level_start(card
, level
);
307 if (card
&& card
->set_bias_level
)
308 ret
= card
->set_bias_level(card
, dapm
, level
);
313 if (dapm
->codec
->driver
->set_bias_level
)
314 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
317 dapm
->bias_level
= level
;
318 } else if (!card
|| dapm
!= &card
->dapm
) {
319 dapm
->bias_level
= level
;
325 if (card
&& card
->set_bias_level_post
)
326 ret
= card
->set_bias_level_post(card
, dapm
, level
);
328 trace_snd_soc_bias_level_done(card
, level
);
333 /* set up initial codec paths */
334 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
335 struct snd_soc_dapm_path
*p
, int i
)
338 case snd_soc_dapm_switch
:
339 case snd_soc_dapm_mixer
:
340 case snd_soc_dapm_mixer_named_ctl
: {
342 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
343 w
->kcontrol_news
[i
].private_value
;
344 unsigned int reg
= mc
->reg
;
345 unsigned int shift
= mc
->shift
;
347 unsigned int mask
= (1 << fls(max
)) - 1;
348 unsigned int invert
= mc
->invert
;
350 val
= soc_widget_read(w
, reg
);
351 val
= (val
>> shift
) & mask
;
358 case snd_soc_dapm_mux
: {
359 struct soc_enum
*e
= (struct soc_enum
*)
360 w
->kcontrol_news
[i
].private_value
;
363 val
= soc_widget_read(w
, e
->reg
);
364 item
= (val
>> e
->shift_l
) & e
->mask
;
367 for (i
= 0; i
< e
->max
; i
++) {
368 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
373 case snd_soc_dapm_virt_mux
: {
374 struct soc_enum
*e
= (struct soc_enum
*)
375 w
->kcontrol_news
[i
].private_value
;
378 /* since a virtual mux has no backing registers to
379 * decide which path to connect, it will try to match
380 * with the first enumeration. This is to ensure
381 * that the default mux choice (the first) will be
382 * correctly powered up during initialization.
384 if (!strcmp(p
->name
, e
->texts
[0]))
388 case snd_soc_dapm_value_mux
: {
389 struct soc_enum
*e
= (struct soc_enum
*)
390 w
->kcontrol_news
[i
].private_value
;
393 val
= soc_widget_read(w
, e
->reg
);
394 val
= (val
>> e
->shift_l
) & e
->mask
;
395 for (item
= 0; item
< e
->max
; item
++) {
396 if (val
== e
->values
[item
])
401 for (i
= 0; i
< e
->max
; i
++) {
402 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
407 /* does not affect routing - always connected */
408 case snd_soc_dapm_pga
:
409 case snd_soc_dapm_out_drv
:
410 case snd_soc_dapm_output
:
411 case snd_soc_dapm_adc
:
412 case snd_soc_dapm_input
:
413 case snd_soc_dapm_siggen
:
414 case snd_soc_dapm_dac
:
415 case snd_soc_dapm_micbias
:
416 case snd_soc_dapm_vmid
:
417 case snd_soc_dapm_supply
:
418 case snd_soc_dapm_regulator_supply
:
419 case snd_soc_dapm_clock_supply
:
420 case snd_soc_dapm_aif_in
:
421 case snd_soc_dapm_aif_out
:
422 case snd_soc_dapm_dai
:
423 case snd_soc_dapm_hp
:
424 case snd_soc_dapm_mic
:
425 case snd_soc_dapm_spk
:
426 case snd_soc_dapm_line
:
427 case snd_soc_dapm_dai_link
:
430 /* does affect routing - dynamically connected */
431 case snd_soc_dapm_pre
:
432 case snd_soc_dapm_post
:
438 /* connect mux widget to its interconnecting audio paths */
439 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
440 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
441 struct snd_soc_dapm_path
*path
, const char *control_name
,
442 const struct snd_kcontrol_new
*kcontrol
)
444 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
447 for (i
= 0; i
< e
->max
; i
++) {
448 if (!(strcmp(control_name
, e
->texts
[i
]))) {
449 list_add(&path
->list
, &dapm
->card
->paths
);
450 list_add(&path
->list_sink
, &dest
->sources
);
451 list_add(&path
->list_source
, &src
->sinks
);
452 path
->name
= (char*)e
->texts
[i
];
453 dapm_set_path_status(dest
, path
, 0);
461 /* connect mixer widget to its interconnecting audio paths */
462 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
463 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
464 struct snd_soc_dapm_path
*path
, const char *control_name
)
468 /* search for mixer kcontrol */
469 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
470 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
471 list_add(&path
->list
, &dapm
->card
->paths
);
472 list_add(&path
->list_sink
, &dest
->sources
);
473 list_add(&path
->list_source
, &src
->sinks
);
474 path
->name
= dest
->kcontrol_news
[i
].name
;
475 dapm_set_path_status(dest
, path
, i
);
482 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
483 struct snd_soc_dapm_widget
*kcontrolw
,
484 const struct snd_kcontrol_new
*kcontrol_new
,
485 struct snd_kcontrol
**kcontrol
)
487 struct snd_soc_dapm_widget
*w
;
492 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
493 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
495 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
496 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
498 *kcontrol
= w
->kcontrols
[i
];
507 /* create new dapm mixer control */
508 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
510 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
512 size_t name_len
, prefix_len
;
513 struct snd_soc_dapm_path
*path
;
514 struct snd_card
*card
= dapm
->card
->snd_card
;
516 struct snd_soc_dapm_widget_list
*wlist
;
520 prefix
= dapm
->codec
->name_prefix
;
525 prefix_len
= strlen(prefix
) + 1;
530 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
533 list_for_each_entry(path
, &w
->sources
, list_sink
) {
535 /* mixer/mux paths name must match control name */
536 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
539 if (w
->kcontrols
[i
]) {
540 path
->kcontrol
= w
->kcontrols
[i
];
544 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
545 sizeof(struct snd_soc_dapm_widget
*),
546 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
549 "asoc: can't allocate widget list for %s\n",
553 wlist
->num_widgets
= 1;
554 wlist
->widgets
[0] = w
;
556 /* add dapm control with long name.
557 * for dapm_mixer this is the concatenation of the
558 * mixer and kcontrol name.
559 * for dapm_mixer_named_ctl this is simply the
562 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
563 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
564 name_len
+= 1 + strlen(w
->name
);
566 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
568 if (path
->long_name
== NULL
) {
575 /* The control will get a prefix from
576 * the control creation process but
577 * we're also using the same prefix
578 * for widgets so cut the prefix off
579 * the front of the widget name.
581 snprintf((char *)path
->long_name
, name_len
,
582 "%s %s", w
->name
+ prefix_len
,
583 w
->kcontrol_news
[i
].name
);
585 case snd_soc_dapm_mixer_named_ctl
:
586 snprintf((char *)path
->long_name
, name_len
,
587 "%s", w
->kcontrol_news
[i
].name
);
591 ((char *)path
->long_name
)[name_len
- 1] = '\0';
593 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
594 wlist
, path
->long_name
,
596 ret
= snd_ctl_add(card
, path
->kcontrol
);
599 "asoc: failed to add dapm kcontrol %s: %d\n",
600 path
->long_name
, ret
);
602 kfree(path
->long_name
);
603 path
->long_name
= NULL
;
606 w
->kcontrols
[i
] = path
->kcontrol
;
612 /* create new dapm mux control */
613 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
615 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
616 struct snd_soc_dapm_path
*path
= NULL
;
617 struct snd_kcontrol
*kcontrol
;
618 struct snd_card
*card
= dapm
->card
->snd_card
;
622 struct snd_soc_dapm_widget_list
*wlist
;
623 int shared
, wlistentries
;
627 if (w
->num_kcontrols
!= 1) {
629 "asoc: mux %s has incorrect number of controls\n",
634 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
637 wlist
= kcontrol
->private_data
;
638 wlistentries
= wlist
->num_widgets
+ 1;
643 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
644 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
645 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
648 "asoc: can't allocate widget list for %s\n", w
->name
);
651 wlist
->num_widgets
= wlistentries
;
652 wlist
->widgets
[wlistentries
- 1] = w
;
656 prefix
= dapm
->codec
->name_prefix
;
661 name
= w
->kcontrol_news
[0].name
;
666 prefix_len
= strlen(prefix
) + 1;
672 * The control will get a prefix from the control creation
673 * process but we're also using the same prefix for widgets so
674 * cut the prefix off the front of the widget name.
676 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
677 name
+ prefix_len
, prefix
);
678 ret
= snd_ctl_add(card
, kcontrol
);
680 dev_err(dapm
->dev
, "failed to add kcontrol %s: %d\n",
687 kcontrol
->private_data
= wlist
;
689 w
->kcontrols
[0] = kcontrol
;
691 list_for_each_entry(path
, &w
->sources
, list_sink
)
692 path
->kcontrol
= kcontrol
;
697 /* create new dapm volume control */
698 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
700 if (w
->num_kcontrols
)
701 dev_err(w
->dapm
->dev
,
702 "asoc: PGA controls not supported: '%s'\n", w
->name
);
707 /* reset 'walked' bit for each dapm path */
708 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
710 struct snd_soc_dapm_path
*p
;
712 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
716 /* We implement power down on suspend by checking the power state of
717 * the ALSA card - when we are suspending the ALSA state for the card
720 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
722 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
725 case SNDRV_CTL_POWER_D3hot
:
726 case SNDRV_CTL_POWER_D3cold
:
727 if (widget
->ignore_suspend
)
728 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
730 return widget
->ignore_suspend
;
736 /* add widget to list if it's not already in the list */
737 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
738 struct snd_soc_dapm_widget
*w
)
740 struct snd_soc_dapm_widget_list
*wlist
;
741 int wlistsize
, wlistentries
, i
;
748 /* is this widget already in the list */
749 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
750 if (wlist
->widgets
[i
] == w
)
754 /* allocate some new space */
755 wlistentries
= wlist
->num_widgets
+ 1;
756 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
757 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
758 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
760 dev_err(w
->dapm
->dev
, "can't allocate widget list for %s\n",
766 /* insert the widget */
767 dev_dbg(w
->dapm
->dev
, "added %s in widget list pos %d\n",
768 w
->name
, wlist
->num_widgets
);
770 wlist
->widgets
[wlist
->num_widgets
] = w
;
771 wlist
->num_widgets
++;
776 * Recursively check for a completed path to an active or physically connected
777 * output widget. Returns number of complete paths.
779 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
780 struct snd_soc_dapm_widget_list
**list
)
782 struct snd_soc_dapm_path
*path
;
785 if (widget
->outputs
>= 0)
786 return widget
->outputs
;
788 DAPM_UPDATE_STAT(widget
, path_checks
);
790 switch (widget
->id
) {
791 case snd_soc_dapm_supply
:
792 case snd_soc_dapm_regulator_supply
:
793 case snd_soc_dapm_clock_supply
:
799 switch (widget
->id
) {
800 case snd_soc_dapm_adc
:
801 case snd_soc_dapm_aif_out
:
802 case snd_soc_dapm_dai
:
803 if (widget
->active
) {
804 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
805 return widget
->outputs
;
811 if (widget
->connected
) {
812 /* connected pin ? */
813 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
814 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
815 return widget
->outputs
;
818 /* connected jack or spk ? */
819 if (widget
->id
== snd_soc_dapm_hp
||
820 widget
->id
== snd_soc_dapm_spk
||
821 (widget
->id
== snd_soc_dapm_line
&&
822 !list_empty(&widget
->sources
))) {
823 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
824 return widget
->outputs
;
828 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
829 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
837 trace_snd_soc_dapm_output_path(widget
, path
);
839 if (path
->sink
&& path
->connect
) {
842 /* do we need to add this widget to the list ? */
845 err
= dapm_list_add_widget(list
, path
->sink
);
847 dev_err(widget
->dapm
->dev
, "could not add widget %s\n",
853 con
+= is_connected_output_ep(path
->sink
, list
);
857 widget
->outputs
= con
;
863 * Recursively check for a completed path to an active or physically connected
864 * input widget. Returns number of complete paths.
866 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
867 struct snd_soc_dapm_widget_list
**list
)
869 struct snd_soc_dapm_path
*path
;
872 if (widget
->inputs
>= 0)
873 return widget
->inputs
;
875 DAPM_UPDATE_STAT(widget
, path_checks
);
877 switch (widget
->id
) {
878 case snd_soc_dapm_supply
:
879 case snd_soc_dapm_regulator_supply
:
880 case snd_soc_dapm_clock_supply
:
886 /* active stream ? */
887 switch (widget
->id
) {
888 case snd_soc_dapm_dac
:
889 case snd_soc_dapm_aif_in
:
890 case snd_soc_dapm_dai
:
891 if (widget
->active
) {
892 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
893 return widget
->inputs
;
899 if (widget
->connected
) {
900 /* connected pin ? */
901 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
902 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
903 return widget
->inputs
;
906 /* connected VMID/Bias for lower pops */
907 if (widget
->id
== snd_soc_dapm_vmid
) {
908 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
909 return widget
->inputs
;
912 /* connected jack ? */
913 if (widget
->id
== snd_soc_dapm_mic
||
914 (widget
->id
== snd_soc_dapm_line
&&
915 !list_empty(&widget
->sinks
))) {
916 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
917 return widget
->inputs
;
920 /* signal generator */
921 if (widget
->id
== snd_soc_dapm_siggen
) {
922 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
923 return widget
->inputs
;
927 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
928 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
936 trace_snd_soc_dapm_input_path(widget
, path
);
938 if (path
->source
&& path
->connect
) {
941 /* do we need to add this widget to the list ? */
944 err
= dapm_list_add_widget(list
, path
->source
);
946 dev_err(widget
->dapm
->dev
, "could not add widget %s\n",
952 con
+= is_connected_input_ep(path
->source
, list
);
956 widget
->inputs
= con
;
962 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
964 * @stream: stream direction.
965 * @list: list of active widgets for this stream.
967 * Queries DAPM graph as to whether an valid audio stream path exists for
968 * the initial stream specified by name. This takes into account
969 * current mixer and mux kcontrol settings. Creates list of valid widgets.
971 * Returns the number of valid paths or negative error.
973 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
974 struct snd_soc_dapm_widget_list
**list
)
976 struct snd_soc_card
*card
= dai
->card
;
979 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
982 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
983 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
985 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
987 trace_snd_soc_dapm_connected(paths
, stream
);
988 dapm_clear_walk(&card
->dapm
);
989 mutex_unlock(&card
->dapm_mutex
);
995 * Handler for generic register modifier widget.
997 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
998 struct snd_kcontrol
*kcontrol
, int event
)
1002 if (SND_SOC_DAPM_EVENT_ON(event
))
1007 soc_widget_update_bits_locked(w
, -(w
->reg
+ 1),
1008 w
->mask
<< w
->shift
, val
<< w
->shift
);
1012 EXPORT_SYMBOL_GPL(dapm_reg_event
);
1015 * Handler for regulator supply widget.
1017 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1018 struct snd_kcontrol
*kcontrol
, int event
)
1022 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1023 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1024 ret
= regulator_allow_bypass(w
->regulator
, true);
1026 dev_warn(w
->dapm
->dev
,
1027 "Failed to bypass %s: %d\n",
1031 return regulator_enable(w
->regulator
);
1033 if (w
->invert
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1034 ret
= regulator_allow_bypass(w
->regulator
, false);
1036 dev_warn(w
->dapm
->dev
,
1037 "Failed to unbypass %s: %d\n",
1041 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1044 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1047 * Handler for clock supply widget.
1049 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1050 struct snd_kcontrol
*kcontrol
, int event
)
1055 #ifdef CONFIG_HAVE_CLK
1056 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1057 return clk_enable(w
->clk
);
1059 clk_disable(w
->clk
);
1065 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1067 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1069 if (w
->power_checked
)
1070 return w
->new_power
;
1075 w
->new_power
= w
->power_check(w
);
1077 w
->power_checked
= true;
1079 return w
->new_power
;
1082 /* Generic check to see if a widget should be powered.
1084 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1088 DAPM_UPDATE_STAT(w
, power_checks
);
1090 in
= is_connected_input_ep(w
, NULL
);
1091 dapm_clear_walk(w
->dapm
);
1092 out
= is_connected_output_ep(w
, NULL
);
1093 dapm_clear_walk(w
->dapm
);
1094 return out
!= 0 && in
!= 0;
1097 static int dapm_dai_check_power(struct snd_soc_dapm_widget
*w
)
1099 DAPM_UPDATE_STAT(w
, power_checks
);
1104 return dapm_generic_check_power(w
);
1107 /* Check to see if an ADC has power */
1108 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
1112 DAPM_UPDATE_STAT(w
, power_checks
);
1115 in
= is_connected_input_ep(w
, NULL
);
1116 dapm_clear_walk(w
->dapm
);
1119 return dapm_generic_check_power(w
);
1123 /* Check to see if a DAC has power */
1124 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
1128 DAPM_UPDATE_STAT(w
, power_checks
);
1131 out
= is_connected_output_ep(w
, NULL
);
1132 dapm_clear_walk(w
->dapm
);
1135 return dapm_generic_check_power(w
);
1139 /* Check to see if a power supply is needed */
1140 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1142 struct snd_soc_dapm_path
*path
;
1144 DAPM_UPDATE_STAT(w
, power_checks
);
1146 /* Check if one of our outputs is connected */
1147 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1148 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1153 if (path
->connected
&&
1154 !path
->connected(path
->source
, path
->sink
))
1160 if (dapm_widget_power_check(path
->sink
))
1164 dapm_clear_walk(w
->dapm
);
1169 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1174 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1175 struct snd_soc_dapm_widget
*b
,
1183 sort
= dapm_down_seq
;
1185 if (sort
[a
->id
] != sort
[b
->id
])
1186 return sort
[a
->id
] - sort
[b
->id
];
1187 if (a
->subseq
!= b
->subseq
) {
1189 return a
->subseq
- b
->subseq
;
1191 return b
->subseq
- a
->subseq
;
1193 if (a
->reg
!= b
->reg
)
1194 return a
->reg
- b
->reg
;
1195 if (a
->dapm
!= b
->dapm
)
1196 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1201 /* Insert a widget in order into a DAPM power sequence. */
1202 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1203 struct list_head
*list
,
1206 struct snd_soc_dapm_widget
*w
;
1208 list_for_each_entry(w
, list
, power_list
)
1209 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1210 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1214 list_add_tail(&new_widget
->power_list
, list
);
1217 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
1218 struct snd_soc_dapm_widget
*w
, int event
)
1220 struct snd_soc_card
*card
= dapm
->card
;
1221 const char *ev_name
;
1225 case SND_SOC_DAPM_PRE_PMU
:
1226 ev_name
= "PRE_PMU";
1229 case SND_SOC_DAPM_POST_PMU
:
1230 ev_name
= "POST_PMU";
1233 case SND_SOC_DAPM_PRE_PMD
:
1234 ev_name
= "PRE_PMD";
1237 case SND_SOC_DAPM_POST_PMD
:
1238 ev_name
= "POST_PMD";
1246 if (w
->power
!= power
)
1249 if (w
->event
&& (w
->event_flags
& event
)) {
1250 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1252 trace_snd_soc_dapm_widget_event_start(w
, event
);
1253 ret
= w
->event(w
, NULL
, event
);
1254 trace_snd_soc_dapm_widget_event_done(w
, event
);
1256 pr_err("%s: %s event failed: %d\n",
1257 ev_name
, w
->name
, ret
);
1261 /* Apply the coalesced changes from a DAPM sequence */
1262 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
1263 struct list_head
*pending
)
1265 struct snd_soc_card
*card
= dapm
->card
;
1266 struct snd_soc_dapm_widget
*w
;
1268 unsigned int value
= 0;
1269 unsigned int mask
= 0;
1270 unsigned int cur_mask
;
1272 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1275 list_for_each_entry(w
, pending
, power_list
) {
1276 cur_mask
= 1 << w
->shift
;
1277 BUG_ON(reg
!= w
->reg
);
1288 pop_dbg(dapm
->dev
, card
->pop_time
,
1289 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1290 w
->name
, reg
, value
, mask
);
1292 /* Check for events */
1293 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
1294 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
1298 /* Any widget will do, they should all be updating the
1301 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1304 pop_dbg(dapm
->dev
, card
->pop_time
,
1305 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1306 value
, mask
, reg
, card
->pop_time
);
1307 pop_wait(card
->pop_time
);
1308 soc_widget_update_bits_locked(w
, reg
, mask
, value
);
1311 list_for_each_entry(w
, pending
, power_list
) {
1312 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
1313 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
1317 /* Apply a DAPM power sequence.
1319 * We walk over a pre-sorted list of widgets to apply power to. In
1320 * order to minimise the number of writes to the device required
1321 * multiple widgets will be updated in a single write where possible.
1322 * Currently anything that requires more than a single write is not
1325 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
1326 struct list_head
*list
, int event
, bool power_up
)
1328 struct snd_soc_dapm_widget
*w
, *n
;
1331 int cur_subseq
= -1;
1332 int cur_reg
= SND_SOC_NOPM
;
1333 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1340 sort
= dapm_down_seq
;
1342 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1345 /* Do we need to apply any queued changes? */
1346 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1347 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1348 if (!list_empty(&pending
))
1349 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1351 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1352 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1353 if (sort
[i
] == cur_sort
)
1354 cur_dapm
->seq_notifier(cur_dapm
,
1359 INIT_LIST_HEAD(&pending
);
1361 cur_subseq
= INT_MIN
;
1362 cur_reg
= SND_SOC_NOPM
;
1367 case snd_soc_dapm_pre
:
1369 list_for_each_entry_safe_continue(w
, n
, list
,
1372 if (event
== SND_SOC_DAPM_STREAM_START
)
1374 NULL
, SND_SOC_DAPM_PRE_PMU
);
1375 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1377 NULL
, SND_SOC_DAPM_PRE_PMD
);
1380 case snd_soc_dapm_post
:
1382 list_for_each_entry_safe_continue(w
, n
, list
,
1385 if (event
== SND_SOC_DAPM_STREAM_START
)
1387 NULL
, SND_SOC_DAPM_POST_PMU
);
1388 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1390 NULL
, SND_SOC_DAPM_POST_PMD
);
1394 /* Queue it up for application */
1395 cur_sort
= sort
[w
->id
];
1396 cur_subseq
= w
->subseq
;
1399 list_move(&w
->power_list
, &pending
);
1404 dev_err(w
->dapm
->dev
,
1405 "Failed to apply widget power: %d\n", ret
);
1408 if (!list_empty(&pending
))
1409 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1411 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1412 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1413 if (sort
[i
] == cur_sort
)
1414 cur_dapm
->seq_notifier(cur_dapm
,
1419 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1421 struct snd_soc_dapm_update
*update
= dapm
->update
;
1422 struct snd_soc_dapm_widget
*w
;
1431 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1432 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1434 pr_err("%s DAPM pre-event failed: %d\n",
1438 ret
= soc_widget_update_bits_locked(w
, update
->reg
, update
->mask
,
1441 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1444 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1445 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1447 pr_err("%s DAPM post-event failed: %d\n",
1452 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1453 * they're changing state.
1455 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1457 struct snd_soc_dapm_context
*d
= data
;
1460 /* If we're off and we're not supposed to be go into STANDBY */
1461 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1462 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1464 pm_runtime_get_sync(d
->dev
);
1466 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1469 "Failed to turn on bias: %d\n", ret
);
1472 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1473 if (d
->bias_level
!= d
->target_bias_level
) {
1474 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1477 "Failed to prepare bias: %d\n", ret
);
1481 /* Async callback run prior to DAPM sequences - brings to their final
1484 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1486 struct snd_soc_dapm_context
*d
= data
;
1489 /* If we just powered the last thing off drop to standby bias */
1490 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1491 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1492 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1493 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1495 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1499 /* If we're in standby and can support bias off then do that */
1500 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1501 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1502 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1504 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1507 pm_runtime_put(d
->dev
);
1510 /* If we just powered up then move to active bias */
1511 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1512 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1513 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1515 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1520 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1521 bool power
, bool connect
)
1523 /* If a connection is being made or broken then that update
1524 * will have marked the peer dirty, otherwise the widgets are
1525 * not connected and this update has no impact. */
1529 /* If the peer is already in the state we're moving to then we
1530 * won't have an impact on it. */
1531 if (power
!= peer
->power
)
1532 dapm_mark_dirty(peer
, "peer state change");
1535 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1536 struct list_head
*up_list
,
1537 struct list_head
*down_list
)
1539 struct snd_soc_dapm_path
*path
;
1541 if (w
->power
== power
)
1544 trace_snd_soc_dapm_widget_power(w
, power
);
1546 /* If we changed our power state perhaps our neigbours changed
1549 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1551 dapm_widget_set_peer_power(path
->source
, power
,
1556 case snd_soc_dapm_supply
:
1557 case snd_soc_dapm_regulator_supply
:
1558 case snd_soc_dapm_clock_supply
:
1559 /* Supplies can't affect their outputs, only their inputs */
1562 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1564 dapm_widget_set_peer_power(path
->sink
, power
,
1572 dapm_seq_insert(w
, up_list
, true);
1574 dapm_seq_insert(w
, down_list
, false);
1579 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1580 struct list_head
*up_list
,
1581 struct list_head
*down_list
)
1586 case snd_soc_dapm_pre
:
1587 dapm_seq_insert(w
, down_list
, false);
1589 case snd_soc_dapm_post
:
1590 dapm_seq_insert(w
, up_list
, true);
1594 power
= dapm_widget_power_check(w
);
1596 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1602 * Scan each dapm widget for complete audio path.
1603 * A complete path is a route that has valid endpoints i.e.:-
1605 * o DAC to output pin.
1606 * o Input Pin to ADC.
1607 * o Input pin to Output pin (bypass, sidetone)
1608 * o DAC to ADC (loopback).
1610 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1612 struct snd_soc_card
*card
= dapm
->card
;
1613 struct snd_soc_dapm_widget
*w
;
1614 struct snd_soc_dapm_context
*d
;
1616 LIST_HEAD(down_list
);
1617 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1618 enum snd_soc_bias_level bias
;
1620 trace_snd_soc_dapm_start(card
);
1622 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1623 if (d
->idle_bias_off
)
1624 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1626 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1631 /* Check which widgets we need to power and store them in
1632 * lists indicating if they should be powered up or down. We
1633 * only check widgets that have been flagged as dirty but note
1634 * that new widgets may be added to the dirty list while we
1637 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1638 dapm_power_one_widget(w
, &up_list
, &down_list
);
1641 list_for_each_entry(w
, &card
->widgets
, list
) {
1643 case snd_soc_dapm_pre
:
1644 case snd_soc_dapm_post
:
1645 /* These widgets always need to be powered */
1648 list_del_init(&w
->dirty
);
1655 /* Supplies and micbiases only bring the
1656 * context up to STANDBY as unless something
1657 * else is active and passing audio they
1658 * generally don't require full power. Signal
1659 * generators are virtual pins and have no
1660 * power impact themselves.
1663 case snd_soc_dapm_siggen
:
1665 case snd_soc_dapm_supply
:
1666 case snd_soc_dapm_regulator_supply
:
1667 case snd_soc_dapm_clock_supply
:
1668 case snd_soc_dapm_micbias
:
1669 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1670 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1673 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1680 /* Force all contexts in the card to the same bias state if
1681 * they're not ground referenced.
1683 bias
= SND_SOC_BIAS_OFF
;
1684 list_for_each_entry(d
, &card
->dapm_list
, list
)
1685 if (d
->target_bias_level
> bias
)
1686 bias
= d
->target_bias_level
;
1687 list_for_each_entry(d
, &card
->dapm_list
, list
)
1688 if (!d
->idle_bias_off
)
1689 d
->target_bias_level
= bias
;
1691 trace_snd_soc_dapm_walk_done(card
);
1693 /* Run all the bias changes in parallel */
1694 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1695 async_schedule_domain(dapm_pre_sequence_async
, d
,
1697 async_synchronize_full_domain(&async_domain
);
1699 /* Power down widgets first; try to avoid amplifying pops. */
1700 dapm_seq_run(dapm
, &down_list
, event
, false);
1702 dapm_widget_update(dapm
);
1705 dapm_seq_run(dapm
, &up_list
, event
, true);
1707 /* Run all the bias changes in parallel */
1708 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1709 async_schedule_domain(dapm_post_sequence_async
, d
,
1711 async_synchronize_full_domain(&async_domain
);
1713 /* do we need to notify any clients that DAPM event is complete */
1714 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1715 if (d
->stream_event
)
1716 d
->stream_event(d
, event
);
1719 pop_dbg(dapm
->dev
, card
->pop_time
,
1720 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1721 pop_wait(card
->pop_time
);
1723 trace_snd_soc_dapm_done(card
);
1728 #ifdef CONFIG_DEBUG_FS
1729 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1730 char __user
*user_buf
,
1731 size_t count
, loff_t
*ppos
)
1733 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1737 struct snd_soc_dapm_path
*p
= NULL
;
1739 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1743 in
= is_connected_input_ep(w
, NULL
);
1744 dapm_clear_walk(w
->dapm
);
1745 out
= is_connected_output_ep(w
, NULL
);
1746 dapm_clear_walk(w
->dapm
);
1748 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1749 w
->name
, w
->power
? "On" : "Off",
1750 w
->force
? " (forced)" : "", in
, out
);
1753 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1754 " - R%d(0x%x) bit %d",
1755 w
->reg
, w
->reg
, w
->shift
);
1757 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1760 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1762 w
->active
? "active" : "inactive");
1764 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1765 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1769 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1770 " in \"%s\" \"%s\"\n",
1771 p
->name
? p
->name
: "static",
1774 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1775 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1779 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1780 " out \"%s\" \"%s\"\n",
1781 p
->name
? p
->name
: "static",
1785 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1791 static const struct file_operations dapm_widget_power_fops
= {
1792 .open
= simple_open
,
1793 .read
= dapm_widget_power_read_file
,
1794 .llseek
= default_llseek
,
1797 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1798 size_t count
, loff_t
*ppos
)
1800 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1803 switch (dapm
->bias_level
) {
1804 case SND_SOC_BIAS_ON
:
1807 case SND_SOC_BIAS_PREPARE
:
1808 level
= "Prepare\n";
1810 case SND_SOC_BIAS_STANDBY
:
1811 level
= "Standby\n";
1813 case SND_SOC_BIAS_OFF
:
1818 level
= "Unknown\n";
1822 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1826 static const struct file_operations dapm_bias_fops
= {
1827 .open
= simple_open
,
1828 .read
= dapm_bias_read_file
,
1829 .llseek
= default_llseek
,
1832 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1833 struct dentry
*parent
)
1837 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1839 if (!dapm
->debugfs_dapm
) {
1841 "Failed to create DAPM debugfs directory\n");
1845 d
= debugfs_create_file("bias_level", 0444,
1846 dapm
->debugfs_dapm
, dapm
,
1850 "ASoC: Failed to create bias level debugfs file\n");
1853 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1855 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1858 if (!dapm
->debugfs_dapm
|| !w
->name
)
1861 d
= debugfs_create_file(w
->name
, 0444,
1862 dapm
->debugfs_dapm
, w
,
1863 &dapm_widget_power_fops
);
1865 dev_warn(w
->dapm
->dev
,
1866 "ASoC: Failed to create %s debugfs file\n",
1870 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1872 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1876 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1877 struct dentry
*parent
)
1881 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1885 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1891 /* test and update the power status of a mux widget */
1892 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1893 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1895 struct snd_soc_dapm_path
*path
;
1898 if (widget
->id
!= snd_soc_dapm_mux
&&
1899 widget
->id
!= snd_soc_dapm_virt_mux
&&
1900 widget
->id
!= snd_soc_dapm_value_mux
)
1903 /* find dapm widget path assoc with kcontrol */
1904 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1905 if (path
->kcontrol
!= kcontrol
)
1908 if (!path
->name
|| !e
->texts
[mux
])
1912 /* we now need to match the string in the enum to the path */
1913 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
1914 path
->connect
= 1; /* new connection */
1915 dapm_mark_dirty(path
->source
, "mux connection");
1918 dapm_mark_dirty(path
->source
,
1919 "mux disconnection");
1920 path
->connect
= 0; /* old connection must be powered down */
1925 dapm_mark_dirty(widget
, "mux change");
1926 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1932 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1933 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1935 struct snd_soc_card
*card
= widget
->dapm
->card
;
1938 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1939 ret
= soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
1940 mutex_unlock(&card
->dapm_mutex
);
1942 soc_dpcm_runtime_update(widget
);
1945 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
1947 /* test and update the power status of a mixer or switch widget */
1948 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1949 struct snd_kcontrol
*kcontrol
, int connect
)
1951 struct snd_soc_dapm_path
*path
;
1954 if (widget
->id
!= snd_soc_dapm_mixer
&&
1955 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1956 widget
->id
!= snd_soc_dapm_switch
)
1959 /* find dapm widget path assoc with kcontrol */
1960 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1961 if (path
->kcontrol
!= kcontrol
)
1964 /* found, now check type */
1966 path
->connect
= connect
;
1967 dapm_mark_dirty(path
->source
, "mixer connection");
1971 dapm_mark_dirty(widget
, "mixer update");
1972 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1978 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1979 struct snd_kcontrol
*kcontrol
, int connect
)
1981 struct snd_soc_card
*card
= widget
->dapm
->card
;
1984 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1985 ret
= soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
1986 mutex_unlock(&card
->dapm_mutex
);
1988 soc_dpcm_runtime_update(widget
);
1991 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
1993 /* show dapm widget status in sys fs */
1994 static ssize_t
dapm_widget_show(struct device
*dev
,
1995 struct device_attribute
*attr
, char *buf
)
1997 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
1998 struct snd_soc_codec
*codec
=rtd
->codec
;
1999 struct snd_soc_dapm_widget
*w
;
2001 char *state
= "not set";
2003 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
2004 if (w
->dapm
!= &codec
->dapm
)
2007 /* only display widgets that burnm power */
2009 case snd_soc_dapm_hp
:
2010 case snd_soc_dapm_mic
:
2011 case snd_soc_dapm_spk
:
2012 case snd_soc_dapm_line
:
2013 case snd_soc_dapm_micbias
:
2014 case snd_soc_dapm_dac
:
2015 case snd_soc_dapm_adc
:
2016 case snd_soc_dapm_pga
:
2017 case snd_soc_dapm_out_drv
:
2018 case snd_soc_dapm_mixer
:
2019 case snd_soc_dapm_mixer_named_ctl
:
2020 case snd_soc_dapm_supply
:
2021 case snd_soc_dapm_regulator_supply
:
2022 case snd_soc_dapm_clock_supply
:
2024 count
+= sprintf(buf
+ count
, "%s: %s\n",
2025 w
->name
, w
->power
? "On":"Off");
2032 switch (codec
->dapm
.bias_level
) {
2033 case SND_SOC_BIAS_ON
:
2036 case SND_SOC_BIAS_PREPARE
:
2039 case SND_SOC_BIAS_STANDBY
:
2042 case SND_SOC_BIAS_OFF
:
2046 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2051 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2053 int snd_soc_dapm_sys_add(struct device
*dev
)
2055 return device_create_file(dev
, &dev_attr_dapm_widget
);
2058 static void snd_soc_dapm_sys_remove(struct device
*dev
)
2060 device_remove_file(dev
, &dev_attr_dapm_widget
);
2063 /* free all dapm widgets and resources */
2064 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2066 struct snd_soc_dapm_widget
*w
, *next_w
;
2067 struct snd_soc_dapm_path
*p
, *next_p
;
2069 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2070 if (w
->dapm
!= dapm
)
2074 * remove source and sink paths associated to this widget.
2075 * While removing the path, remove reference to it from both
2076 * source and sink widgets so that path is removed only once.
2078 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
2079 list_del(&p
->list_sink
);
2080 list_del(&p
->list_source
);
2082 kfree(p
->long_name
);
2085 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
2086 list_del(&p
->list_sink
);
2087 list_del(&p
->list_source
);
2089 kfree(p
->long_name
);
2092 kfree(w
->kcontrols
);
2098 static struct snd_soc_dapm_widget
*dapm_find_widget(
2099 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2100 bool search_other_contexts
)
2102 struct snd_soc_dapm_widget
*w
;
2103 struct snd_soc_dapm_widget
*fallback
= NULL
;
2105 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2106 if (!strcmp(w
->name
, pin
)) {
2107 if (w
->dapm
== dapm
)
2114 if (search_other_contexts
)
2120 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2121 const char *pin
, int status
)
2123 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2126 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2130 if (w
->connected
!= status
)
2131 dapm_mark_dirty(w
, "pin configuration");
2133 w
->connected
= status
;
2141 * snd_soc_dapm_sync - scan and power dapm paths
2142 * @dapm: DAPM context
2144 * Walks all dapm audio paths and powers widgets according to their
2145 * stream or path usage.
2147 * Returns 0 for success.
2149 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2154 * Suppress early reports (eg, jacks syncing their state) to avoid
2155 * silly DAPM runs during card startup.
2157 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2160 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2161 ret
= dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2162 mutex_unlock(&dapm
->card
->dapm_mutex
);
2165 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2167 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2168 const struct snd_soc_dapm_route
*route
)
2170 struct snd_soc_dapm_path
*path
;
2171 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2172 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2174 const char *control
= route
->control
;
2176 char prefixed_sink
[80];
2177 char prefixed_source
[80];
2180 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2181 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2182 dapm
->codec
->name_prefix
, route
->sink
);
2183 sink
= prefixed_sink
;
2184 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2185 dapm
->codec
->name_prefix
, route
->source
);
2186 source
= prefixed_source
;
2189 source
= route
->source
;
2193 * find src and dest widgets over all widgets but favor a widget from
2194 * current DAPM context
2196 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2197 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2199 if (w
->dapm
== dapm
)
2203 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2205 if (w
->dapm
== dapm
)
2209 /* use widget from another DAPM context if not found from this */
2215 if (wsource
== NULL
|| wsink
== NULL
)
2218 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2222 path
->source
= wsource
;
2224 path
->connected
= route
->connected
;
2225 INIT_LIST_HEAD(&path
->list
);
2226 INIT_LIST_HEAD(&path
->list_source
);
2227 INIT_LIST_HEAD(&path
->list_sink
);
2229 /* check for external widgets */
2230 if (wsink
->id
== snd_soc_dapm_input
) {
2231 if (wsource
->id
== snd_soc_dapm_micbias
||
2232 wsource
->id
== snd_soc_dapm_mic
||
2233 wsource
->id
== snd_soc_dapm_line
||
2234 wsource
->id
== snd_soc_dapm_output
)
2237 if (wsource
->id
== snd_soc_dapm_output
) {
2238 if (wsink
->id
== snd_soc_dapm_spk
||
2239 wsink
->id
== snd_soc_dapm_hp
||
2240 wsink
->id
== snd_soc_dapm_line
||
2241 wsink
->id
== snd_soc_dapm_input
)
2245 /* connect static paths */
2246 if (control
== NULL
) {
2247 list_add(&path
->list
, &dapm
->card
->paths
);
2248 list_add(&path
->list_sink
, &wsink
->sources
);
2249 list_add(&path
->list_source
, &wsource
->sinks
);
2254 /* connect dynamic paths */
2255 switch (wsink
->id
) {
2256 case snd_soc_dapm_adc
:
2257 case snd_soc_dapm_dac
:
2258 case snd_soc_dapm_pga
:
2259 case snd_soc_dapm_out_drv
:
2260 case snd_soc_dapm_input
:
2261 case snd_soc_dapm_output
:
2262 case snd_soc_dapm_siggen
:
2263 case snd_soc_dapm_micbias
:
2264 case snd_soc_dapm_vmid
:
2265 case snd_soc_dapm_pre
:
2266 case snd_soc_dapm_post
:
2267 case snd_soc_dapm_supply
:
2268 case snd_soc_dapm_regulator_supply
:
2269 case snd_soc_dapm_clock_supply
:
2270 case snd_soc_dapm_aif_in
:
2271 case snd_soc_dapm_aif_out
:
2272 case snd_soc_dapm_dai
:
2273 case snd_soc_dapm_dai_link
:
2274 list_add(&path
->list
, &dapm
->card
->paths
);
2275 list_add(&path
->list_sink
, &wsink
->sources
);
2276 list_add(&path
->list_source
, &wsource
->sinks
);
2279 case snd_soc_dapm_mux
:
2280 case snd_soc_dapm_virt_mux
:
2281 case snd_soc_dapm_value_mux
:
2282 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2283 &wsink
->kcontrol_news
[0]);
2287 case snd_soc_dapm_switch
:
2288 case snd_soc_dapm_mixer
:
2289 case snd_soc_dapm_mixer_named_ctl
:
2290 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2294 case snd_soc_dapm_hp
:
2295 case snd_soc_dapm_mic
:
2296 case snd_soc_dapm_line
:
2297 case snd_soc_dapm_spk
:
2298 list_add(&path
->list
, &dapm
->card
->paths
);
2299 list_add(&path
->list_sink
, &wsink
->sources
);
2300 list_add(&path
->list_source
, &wsource
->sinks
);
2305 dapm_mark_dirty(wsource
, "Route added");
2306 dapm_mark_dirty(wsink
, "Route added");
2311 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
2312 source
, control
, sink
);
2317 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2318 const struct snd_soc_dapm_route
*route
)
2320 struct snd_soc_dapm_path
*path
, *p
;
2323 char prefixed_sink
[80];
2324 char prefixed_source
[80];
2326 if (route
->control
) {
2328 "Removal of routes with controls not supported\n");
2332 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
2333 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2334 dapm
->codec
->name_prefix
, route
->sink
);
2335 sink
= prefixed_sink
;
2336 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2337 dapm
->codec
->name_prefix
, route
->source
);
2338 source
= prefixed_source
;
2341 source
= route
->source
;
2345 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2346 if (strcmp(p
->source
->name
, source
) != 0)
2348 if (strcmp(p
->sink
->name
, sink
) != 0)
2355 dapm_mark_dirty(path
->source
, "Route removed");
2356 dapm_mark_dirty(path
->sink
, "Route removed");
2358 list_del(&path
->list
);
2359 list_del(&path
->list_sink
);
2360 list_del(&path
->list_source
);
2363 dev_warn(dapm
->dev
, "Route %s->%s does not exist\n",
2371 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2372 * @dapm: DAPM context
2373 * @route: audio routes
2374 * @num: number of routes
2376 * Connects 2 dapm widgets together via a named audio path. The sink is
2377 * the widget receiving the audio signal, whilst the source is the sender
2378 * of the audio signal.
2380 * Returns 0 for success else error. On error all resources can be freed
2381 * with a call to snd_soc_card_free().
2383 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2384 const struct snd_soc_dapm_route
*route
, int num
)
2388 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2389 for (i
= 0; i
< num
; i
++) {
2390 r
= snd_soc_dapm_add_route(dapm
, route
);
2392 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
2393 route
->source
, route
->sink
);
2398 mutex_unlock(&dapm
->card
->dapm_mutex
);
2402 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2405 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2406 * @dapm: DAPM context
2407 * @route: audio routes
2408 * @num: number of routes
2410 * Removes routes from the DAPM context.
2412 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2413 const struct snd_soc_dapm_route
*route
, int num
)
2417 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2418 for (i
= 0; i
< num
; i
++) {
2419 snd_soc_dapm_del_route(dapm
, route
);
2422 mutex_unlock(&dapm
->card
->dapm_mutex
);
2426 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2428 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2429 const struct snd_soc_dapm_route
*route
)
2431 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2434 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2437 struct snd_soc_dapm_path
*path
;
2441 dev_err(dapm
->dev
, "Unable to find source %s for weak route\n",
2447 dev_err(dapm
->dev
, "Unable to find sink %s for weak route\n",
2452 if (route
->control
|| route
->connected
)
2453 dev_warn(dapm
->dev
, "Ignoring control for weak route %s->%s\n",
2454 route
->source
, route
->sink
);
2456 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2457 if (path
->sink
== sink
) {
2464 dev_err(dapm
->dev
, "No path found for weak route %s->%s\n",
2465 route
->source
, route
->sink
);
2467 dev_warn(dapm
->dev
, "%d paths found for weak route %s->%s\n",
2468 count
, route
->source
, route
->sink
);
2474 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2475 * @dapm: DAPM context
2476 * @route: audio routes
2477 * @num: number of routes
2479 * Mark existing routes matching those specified in the passed array
2480 * as being weak, meaning that they are ignored for the purpose of
2481 * power decisions. The main intended use case is for sidetone paths
2482 * which couple audio between other independent paths if they are both
2483 * active in order to make the combination work better at the user
2484 * level but which aren't intended to be "used".
2486 * Note that CODEC drivers should not use this as sidetone type paths
2487 * can frequently also be used as bypass paths.
2489 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2490 const struct snd_soc_dapm_route
*route
, int num
)
2495 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2496 for (i
= 0; i
< num
; i
++) {
2497 err
= snd_soc_dapm_weak_route(dapm
, route
);
2502 mutex_unlock(&dapm
->card
->dapm_mutex
);
2506 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2509 * snd_soc_dapm_new_widgets - add new dapm widgets
2510 * @dapm: DAPM context
2512 * Checks the codec for any new dapm widgets and creates them if found.
2514 * Returns 0 for success.
2516 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
2518 struct snd_soc_dapm_widget
*w
;
2521 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2523 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2528 if (w
->num_kcontrols
) {
2529 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2530 sizeof(struct snd_kcontrol
*),
2532 if (!w
->kcontrols
) {
2533 mutex_unlock(&dapm
->card
->dapm_mutex
);
2539 case snd_soc_dapm_switch
:
2540 case snd_soc_dapm_mixer
:
2541 case snd_soc_dapm_mixer_named_ctl
:
2544 case snd_soc_dapm_mux
:
2545 case snd_soc_dapm_virt_mux
:
2546 case snd_soc_dapm_value_mux
:
2549 case snd_soc_dapm_pga
:
2550 case snd_soc_dapm_out_drv
:
2557 /* Read the initial power state from the device */
2559 val
= soc_widget_read(w
, w
->reg
);
2560 val
&= 1 << w
->shift
;
2570 dapm_mark_dirty(w
, "new widget");
2571 dapm_debugfs_add_widget(w
);
2574 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2575 mutex_unlock(&dapm
->card
->dapm_mutex
);
2578 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2581 * snd_soc_dapm_get_volsw - dapm mixer get callback
2582 * @kcontrol: mixer control
2583 * @ucontrol: control element information
2585 * Callback to get the value of a dapm mixer control.
2587 * Returns 0 for success.
2589 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2590 struct snd_ctl_elem_value
*ucontrol
)
2592 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2593 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
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 if (snd_soc_volsw_is_stereo(mc
))
2603 dev_warn(widget
->dapm
->dev
,
2604 "Control '%s' is stereo, which is not supported\n",
2607 ucontrol
->value
.integer
.value
[0] =
2608 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2610 ucontrol
->value
.integer
.value
[0] =
2611 max
- ucontrol
->value
.integer
.value
[0];
2615 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2618 * snd_soc_dapm_put_volsw - dapm mixer set callback
2619 * @kcontrol: mixer control
2620 * @ucontrol: control element information
2622 * Callback to set the value of a dapm mixer control.
2624 * Returns 0 for success.
2626 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2627 struct snd_ctl_elem_value
*ucontrol
)
2629 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2630 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2631 struct snd_soc_codec
*codec
= widget
->codec
;
2632 struct snd_soc_card
*card
= codec
->card
;
2633 struct soc_mixer_control
*mc
=
2634 (struct soc_mixer_control
*)kcontrol
->private_value
;
2635 unsigned int reg
= mc
->reg
;
2636 unsigned int shift
= mc
->shift
;
2638 unsigned int mask
= (1 << fls(max
)) - 1;
2639 unsigned int invert
= mc
->invert
;
2641 int connect
, change
;
2642 struct snd_soc_dapm_update update
;
2645 if (snd_soc_volsw_is_stereo(mc
))
2646 dev_warn(widget
->dapm
->dev
,
2647 "Control '%s' is stereo, which is not supported\n",
2650 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2655 mask
= mask
<< shift
;
2658 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2660 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2662 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2663 widget
= wlist
->widgets
[wi
];
2665 widget
->value
= val
;
2667 update
.kcontrol
= kcontrol
;
2668 update
.widget
= widget
;
2672 widget
->dapm
->update
= &update
;
2674 soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2676 widget
->dapm
->update
= NULL
;
2680 mutex_unlock(&card
->dapm_mutex
);
2683 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2686 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2687 * @kcontrol: mixer control
2688 * @ucontrol: control element information
2690 * Callback to get the value of a dapm enumerated double mixer control.
2692 * Returns 0 for success.
2694 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2695 struct snd_ctl_elem_value
*ucontrol
)
2697 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2698 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2699 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2702 val
= snd_soc_read(widget
->codec
, e
->reg
);
2703 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & e
->mask
;
2704 if (e
->shift_l
!= e
->shift_r
)
2705 ucontrol
->value
.enumerated
.item
[1] =
2706 (val
>> e
->shift_r
) & e
->mask
;
2710 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2713 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2714 * @kcontrol: mixer control
2715 * @ucontrol: control element information
2717 * Callback to set the value of a dapm enumerated double mixer control.
2719 * Returns 0 for success.
2721 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2722 struct snd_ctl_elem_value
*ucontrol
)
2724 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2725 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2726 struct snd_soc_codec
*codec
= widget
->codec
;
2727 struct snd_soc_card
*card
= codec
->card
;
2728 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2729 unsigned int val
, mux
, change
;
2731 struct snd_soc_dapm_update update
;
2734 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2736 mux
= ucontrol
->value
.enumerated
.item
[0];
2737 val
= mux
<< e
->shift_l
;
2738 mask
= e
->mask
<< e
->shift_l
;
2739 if (e
->shift_l
!= e
->shift_r
) {
2740 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2742 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2743 mask
|= e
->mask
<< e
->shift_r
;
2746 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2748 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2750 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2751 widget
= wlist
->widgets
[wi
];
2753 widget
->value
= val
;
2755 update
.kcontrol
= kcontrol
;
2756 update
.widget
= widget
;
2757 update
.reg
= e
->reg
;
2760 widget
->dapm
->update
= &update
;
2762 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2764 widget
->dapm
->update
= NULL
;
2768 mutex_unlock(&card
->dapm_mutex
);
2771 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2774 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2775 * @kcontrol: mixer control
2776 * @ucontrol: control element information
2778 * Returns 0 for success.
2780 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2781 struct snd_ctl_elem_value
*ucontrol
)
2783 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2784 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2786 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2790 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2793 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2794 * @kcontrol: mixer control
2795 * @ucontrol: control element information
2797 * Returns 0 for success.
2799 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2800 struct snd_ctl_elem_value
*ucontrol
)
2802 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2803 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2804 struct snd_soc_codec
*codec
= widget
->codec
;
2805 struct snd_soc_card
*card
= codec
->card
;
2806 struct soc_enum
*e
=
2807 (struct soc_enum
*)kcontrol
->private_value
;
2812 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2815 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2817 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2819 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2820 widget
= wlist
->widgets
[wi
];
2822 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2824 soc_dapm_mux_update_power(widget
, kcontrol
, widget
->value
, e
);
2828 mutex_unlock(&card
->dapm_mutex
);
2831 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2834 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2836 * @kcontrol: mixer control
2837 * @ucontrol: control element information
2839 * Callback to get the value of a dapm semi enumerated double mixer control.
2841 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2842 * used for handling bitfield coded enumeration for example.
2844 * Returns 0 for success.
2846 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2847 struct snd_ctl_elem_value
*ucontrol
)
2849 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2850 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2851 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2852 unsigned int reg_val
, val
, mux
;
2854 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2855 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2856 for (mux
= 0; mux
< e
->max
; mux
++) {
2857 if (val
== e
->values
[mux
])
2860 ucontrol
->value
.enumerated
.item
[0] = mux
;
2861 if (e
->shift_l
!= e
->shift_r
) {
2862 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2863 for (mux
= 0; mux
< e
->max
; mux
++) {
2864 if (val
== e
->values
[mux
])
2867 ucontrol
->value
.enumerated
.item
[1] = mux
;
2872 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2875 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2877 * @kcontrol: mixer control
2878 * @ucontrol: control element information
2880 * Callback to set the value of a dapm semi enumerated double mixer control.
2882 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2883 * used for handling bitfield coded enumeration for example.
2885 * Returns 0 for success.
2887 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2888 struct snd_ctl_elem_value
*ucontrol
)
2890 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2891 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2892 struct snd_soc_codec
*codec
= widget
->codec
;
2893 struct snd_soc_card
*card
= codec
->card
;
2894 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2895 unsigned int val
, mux
, change
;
2897 struct snd_soc_dapm_update update
;
2900 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2902 mux
= ucontrol
->value
.enumerated
.item
[0];
2903 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2904 mask
= e
->mask
<< e
->shift_l
;
2905 if (e
->shift_l
!= e
->shift_r
) {
2906 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2908 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2909 mask
|= e
->mask
<< e
->shift_r
;
2912 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2914 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2916 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2917 widget
= wlist
->widgets
[wi
];
2919 widget
->value
= val
;
2921 update
.kcontrol
= kcontrol
;
2922 update
.widget
= widget
;
2923 update
.reg
= e
->reg
;
2926 widget
->dapm
->update
= &update
;
2928 soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2930 widget
->dapm
->update
= NULL
;
2934 mutex_unlock(&card
->dapm_mutex
);
2937 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2940 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2942 * @kcontrol: mixer control
2943 * @uinfo: control element information
2945 * Callback to provide information about a pin switch control.
2947 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2948 struct snd_ctl_elem_info
*uinfo
)
2950 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2952 uinfo
->value
.integer
.min
= 0;
2953 uinfo
->value
.integer
.max
= 1;
2957 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2960 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2962 * @kcontrol: mixer control
2965 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2966 struct snd_ctl_elem_value
*ucontrol
)
2968 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2969 const char *pin
= (const char *)kcontrol
->private_value
;
2971 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2973 ucontrol
->value
.integer
.value
[0] =
2974 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
2976 mutex_unlock(&card
->dapm_mutex
);
2980 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2983 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2985 * @kcontrol: mixer control
2988 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2989 struct snd_ctl_elem_value
*ucontrol
)
2991 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2992 const char *pin
= (const char *)kcontrol
->private_value
;
2994 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2996 if (ucontrol
->value
.integer
.value
[0])
2997 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
2999 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3001 mutex_unlock(&card
->dapm_mutex
);
3003 snd_soc_dapm_sync(&card
->dapm
);
3006 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3008 static struct snd_soc_dapm_widget
*
3009 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3010 const struct snd_soc_dapm_widget
*widget
)
3012 struct snd_soc_dapm_widget
*w
;
3016 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3020 case snd_soc_dapm_regulator_supply
:
3021 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3022 if (IS_ERR(w
->regulator
)) {
3023 ret
= PTR_ERR(w
->regulator
);
3024 dev_err(dapm
->dev
, "Failed to request %s: %d\n",
3029 case snd_soc_dapm_clock_supply
:
3030 #ifdef CONFIG_CLKDEV_LOOKUP
3031 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3032 if (IS_ERR(w
->clk
)) {
3033 ret
= PTR_ERR(w
->clk
);
3034 dev_err(dapm
->dev
, "Failed to request %s: %d\n",
3046 name_len
= strlen(widget
->name
) + 1;
3047 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3048 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
3049 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
3050 if (w
->name
== NULL
) {
3054 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
3055 snprintf((char *)w
->name
, name_len
, "%s %s",
3056 dapm
->codec
->name_prefix
, widget
->name
);
3058 snprintf((char *)w
->name
, name_len
, "%s", widget
->name
);
3061 case snd_soc_dapm_switch
:
3062 case snd_soc_dapm_mixer
:
3063 case snd_soc_dapm_mixer_named_ctl
:
3064 w
->power_check
= dapm_generic_check_power
;
3066 case snd_soc_dapm_mux
:
3067 case snd_soc_dapm_virt_mux
:
3068 case snd_soc_dapm_value_mux
:
3069 w
->power_check
= dapm_generic_check_power
;
3071 case snd_soc_dapm_adc
:
3072 case snd_soc_dapm_aif_out
:
3073 w
->power_check
= dapm_adc_check_power
;
3075 case snd_soc_dapm_dac
:
3076 case snd_soc_dapm_aif_in
:
3077 w
->power_check
= dapm_dac_check_power
;
3079 case snd_soc_dapm_pga
:
3080 case snd_soc_dapm_out_drv
:
3081 case snd_soc_dapm_input
:
3082 case snd_soc_dapm_output
:
3083 case snd_soc_dapm_micbias
:
3084 case snd_soc_dapm_spk
:
3085 case snd_soc_dapm_hp
:
3086 case snd_soc_dapm_mic
:
3087 case snd_soc_dapm_line
:
3088 case snd_soc_dapm_dai_link
:
3089 w
->power_check
= dapm_generic_check_power
;
3091 case snd_soc_dapm_supply
:
3092 case snd_soc_dapm_regulator_supply
:
3093 case snd_soc_dapm_clock_supply
:
3094 w
->power_check
= dapm_supply_check_power
;
3096 case snd_soc_dapm_dai
:
3097 w
->power_check
= dapm_dai_check_power
;
3100 w
->power_check
= dapm_always_on_check_power
;
3106 w
->codec
= dapm
->codec
;
3107 w
->platform
= dapm
->platform
;
3108 INIT_LIST_HEAD(&w
->sources
);
3109 INIT_LIST_HEAD(&w
->sinks
);
3110 INIT_LIST_HEAD(&w
->list
);
3111 INIT_LIST_HEAD(&w
->dirty
);
3112 list_add(&w
->list
, &dapm
->card
->widgets
);
3114 /* machine layer set ups unconnected pins and insertions */
3120 * snd_soc_dapm_new_controls - create new dapm controls
3121 * @dapm: DAPM context
3122 * @widget: widget array
3123 * @num: number of widgets
3125 * Creates new DAPM controls based upon the templates.
3127 * Returns 0 for success else error.
3129 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3130 const struct snd_soc_dapm_widget
*widget
,
3133 struct snd_soc_dapm_widget
*w
;
3137 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3138 for (i
= 0; i
< num
; i
++) {
3139 w
= snd_soc_dapm_new_control(dapm
, widget
);
3142 "ASoC: Failed to create DAPM control %s\n",
3149 mutex_unlock(&dapm
->card
->dapm_mutex
);
3152 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3154 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3155 struct snd_kcontrol
*kcontrol
, int event
)
3157 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3158 struct snd_soc_dai
*source
, *sink
;
3159 const struct snd_soc_pcm_stream
*config
= w
->params
;
3160 struct snd_pcm_substream substream
;
3161 struct snd_pcm_hw_params
*params
= NULL
;
3166 BUG_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
));
3168 /* We only support a single source and sink, pick the first */
3169 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3171 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3174 BUG_ON(!source_p
|| !sink_p
);
3175 BUG_ON(!sink_p
->source
|| !source_p
->sink
);
3176 BUG_ON(!source_p
->source
|| !sink_p
->sink
);
3178 source
= source_p
->source
->priv
;
3179 sink
= sink_p
->sink
->priv
;
3181 /* Be a little careful as we don't want to overflow the mask array */
3182 if (config
->formats
) {
3183 fmt
= ffs(config
->formats
) - 1;
3185 dev_warn(w
->dapm
->dev
, "Invalid format %llx specified\n",
3190 /* Currently very limited parameter selection */
3191 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3196 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3198 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3200 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3203 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3204 = config
->channels_min
;
3205 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3206 = config
->channels_max
;
3208 memset(&substream
, 0, sizeof(substream
));
3211 case SND_SOC_DAPM_PRE_PMU
:
3212 if (source
->driver
->ops
&& source
->driver
->ops
->hw_params
) {
3213 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3214 ret
= source
->driver
->ops
->hw_params(&substream
,
3217 dev_err(source
->dev
,
3218 "hw_params() failed: %d\n", ret
);
3223 if (sink
->driver
->ops
&& sink
->driver
->ops
->hw_params
) {
3224 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3225 ret
= sink
->driver
->ops
->hw_params(&substream
, params
,
3229 "hw_params() failed: %d\n", ret
);
3235 case SND_SOC_DAPM_POST_PMU
:
3236 ret
= snd_soc_dai_digital_mute(sink
, 0);
3237 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3238 dev_warn(sink
->dev
, "Failed to unmute: %d\n", ret
);
3242 case SND_SOC_DAPM_PRE_PMD
:
3243 ret
= snd_soc_dai_digital_mute(sink
, 1);
3244 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3245 dev_warn(sink
->dev
, "Failed to mute: %d\n", ret
);
3259 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3260 const struct snd_soc_pcm_stream
*params
,
3261 struct snd_soc_dapm_widget
*source
,
3262 struct snd_soc_dapm_widget
*sink
)
3264 struct snd_soc_dapm_route routes
[2];
3265 struct snd_soc_dapm_widget
template;
3266 struct snd_soc_dapm_widget
*w
;
3270 len
= strlen(source
->name
) + strlen(sink
->name
) + 2;
3271 link_name
= devm_kzalloc(card
->dev
, len
, GFP_KERNEL
);
3274 snprintf(link_name
, len
, "%s-%s", source
->name
, sink
->name
);
3276 memset(&template, 0, sizeof(template));
3277 template.reg
= SND_SOC_NOPM
;
3278 template.id
= snd_soc_dapm_dai_link
;
3279 template.name
= link_name
;
3280 template.event
= snd_soc_dai_link_event
;
3281 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3282 SND_SOC_DAPM_PRE_PMD
;
3284 dev_dbg(card
->dev
, "adding %s widget\n", link_name
);
3286 w
= snd_soc_dapm_new_control(&card
->dapm
, &template);
3288 dev_err(card
->dev
, "Failed to create %s widget\n",
3295 memset(&routes
, 0, sizeof(routes
));
3297 routes
[0].source
= source
->name
;
3298 routes
[0].sink
= link_name
;
3299 routes
[1].source
= link_name
;
3300 routes
[1].sink
= sink
->name
;
3302 return snd_soc_dapm_add_routes(&card
->dapm
, routes
,
3303 ARRAY_SIZE(routes
));
3306 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3307 struct snd_soc_dai
*dai
)
3309 struct snd_soc_dapm_widget
template;
3310 struct snd_soc_dapm_widget
*w
;
3312 WARN_ON(dapm
->dev
!= dai
->dev
);
3314 memset(&template, 0, sizeof(template));
3315 template.reg
= SND_SOC_NOPM
;
3317 if (dai
->driver
->playback
.stream_name
) {
3318 template.id
= snd_soc_dapm_dai
;
3319 template.name
= dai
->driver
->playback
.stream_name
;
3320 template.sname
= dai
->driver
->playback
.stream_name
;
3322 dev_dbg(dai
->dev
, "adding %s widget\n",
3325 w
= snd_soc_dapm_new_control(dapm
, &template);
3327 dev_err(dapm
->dev
, "Failed to create %s widget\n",
3328 dai
->driver
->playback
.stream_name
);
3332 dai
->playback_widget
= w
;
3335 if (dai
->driver
->capture
.stream_name
) {
3336 template.id
= snd_soc_dapm_dai
;
3337 template.name
= dai
->driver
->capture
.stream_name
;
3338 template.sname
= dai
->driver
->capture
.stream_name
;
3340 dev_dbg(dai
->dev
, "adding %s widget\n",
3343 w
= snd_soc_dapm_new_control(dapm
, &template);
3345 dev_err(dapm
->dev
, "Failed to create %s widget\n",
3346 dai
->driver
->capture
.stream_name
);
3350 dai
->capture_widget
= w
;
3356 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3358 struct snd_soc_dapm_widget
*dai_w
, *w
;
3359 struct snd_soc_dai
*dai
;
3360 struct snd_soc_dapm_route r
;
3362 memset(&r
, 0, sizeof(r
));
3364 /* For each DAI widget... */
3365 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3366 if (dai_w
->id
!= snd_soc_dapm_dai
)
3371 /* ...find all widgets with the same stream and link them */
3372 list_for_each_entry(w
, &card
->widgets
, list
) {
3373 if (w
->dapm
!= dai_w
->dapm
)
3376 if (w
->id
== snd_soc_dapm_dai
)
3382 if (dai
->driver
->playback
.stream_name
&&
3384 dai
->driver
->playback
.stream_name
)) {
3385 r
.source
= dai
->playback_widget
->name
;
3387 dev_dbg(dai
->dev
, "%s -> %s\n",
3390 snd_soc_dapm_add_route(w
->dapm
, &r
);
3393 if (dai
->driver
->capture
.stream_name
&&
3395 dai
->driver
->capture
.stream_name
)) {
3397 r
.sink
= dai
->capture_widget
->name
;
3398 dev_dbg(dai
->dev
, "%s -> %s\n",
3401 snd_soc_dapm_add_route(w
->dapm
, &r
);
3409 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3413 struct snd_soc_dapm_widget
*w_cpu
, *w_codec
;
3414 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3415 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
3417 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3418 w_cpu
= cpu_dai
->playback_widget
;
3419 w_codec
= codec_dai
->playback_widget
;
3421 w_cpu
= cpu_dai
->capture_widget
;
3422 w_codec
= codec_dai
->capture_widget
;
3427 dapm_mark_dirty(w_cpu
, "stream event");
3430 case SND_SOC_DAPM_STREAM_START
:
3433 case SND_SOC_DAPM_STREAM_STOP
:
3436 case SND_SOC_DAPM_STREAM_SUSPEND
:
3437 case SND_SOC_DAPM_STREAM_RESUME
:
3438 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3439 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3446 dapm_mark_dirty(w_codec
, "stream event");
3449 case SND_SOC_DAPM_STREAM_START
:
3450 w_codec
->active
= 1;
3452 case SND_SOC_DAPM_STREAM_STOP
:
3453 w_codec
->active
= 0;
3455 case SND_SOC_DAPM_STREAM_SUSPEND
:
3456 case SND_SOC_DAPM_STREAM_RESUME
:
3457 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3458 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3463 dapm_power_widgets(&rtd
->card
->dapm
, event
);
3467 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3468 * @rtd: PCM runtime data
3469 * @stream: stream name
3470 * @event: stream event
3472 * Sends a stream event to the dapm core. The core then makes any
3473 * necessary widget power changes.
3475 * Returns 0 for success else error.
3477 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3480 struct snd_soc_card
*card
= rtd
->card
;
3482 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3483 soc_dapm_stream_event(rtd
, stream
, event
);
3484 mutex_unlock(&card
->dapm_mutex
);
3488 * snd_soc_dapm_enable_pin - enable pin.
3489 * @dapm: DAPM context
3492 * Enables input/output pin and its parents or children widgets iff there is
3493 * a valid audio route and active audio stream.
3494 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3495 * do any widget power switching.
3497 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3499 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3501 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3504 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3505 * @dapm: DAPM context
3508 * Enables input/output pin regardless of any other state. This is
3509 * intended for use with microphone bias supplies used in microphone
3512 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3513 * do any widget power switching.
3515 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3518 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3521 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3525 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
3528 dapm_mark_dirty(w
, "force enable");
3532 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3535 * snd_soc_dapm_disable_pin - disable pin.
3536 * @dapm: DAPM context
3539 * Disables input/output pin and its parents or children widgets.
3540 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3541 * do any widget power switching.
3543 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3546 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3548 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3551 * snd_soc_dapm_nc_pin - permanently disable pin.
3552 * @dapm: DAPM context
3555 * Marks the specified pin as being not connected, disabling it along
3556 * any parent or child widgets. At present this is identical to
3557 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3558 * additional things such as disabling controls which only affect
3559 * paths through the pin.
3561 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3562 * do any widget power switching.
3564 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3566 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3568 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3571 * snd_soc_dapm_get_pin_status - get audio pin status
3572 * @dapm: DAPM context
3573 * @pin: audio signal pin endpoint (or start point)
3575 * Get audio pin status - connected or disconnected.
3577 * Returns 1 for connected otherwise 0.
3579 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3582 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3585 return w
->connected
;
3589 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
3592 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3593 * @dapm: DAPM context
3594 * @pin: audio signal pin endpoint (or start point)
3596 * Mark the given endpoint or pin as ignoring suspend. When the
3597 * system is disabled a path between two endpoints flagged as ignoring
3598 * suspend will not be disabled. The path must already be enabled via
3599 * normal means at suspend time, it will not be turned on if it was not
3602 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
3605 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
3608 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3612 w
->ignore_suspend
= 1;
3616 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
3618 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
3619 struct snd_soc_dapm_widget
*w
)
3621 struct snd_soc_dapm_path
*p
;
3623 list_for_each_entry(p
, &card
->paths
, list
) {
3624 if ((p
->source
== w
) || (p
->sink
== w
)) {
3626 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3627 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
3628 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
3630 /* Connected to something other than the codec */
3631 if (p
->source
->dapm
!= p
->sink
->dapm
)
3634 * Loopback connection from codec external pin to
3635 * codec external pin
3637 if (p
->sink
->id
== snd_soc_dapm_input
) {
3638 switch (p
->source
->id
) {
3639 case snd_soc_dapm_output
:
3640 case snd_soc_dapm_micbias
:
3653 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3654 * @codec: The codec whose pins should be processed
3656 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3657 * which are unused. Pins are used if they are connected externally to the
3658 * codec, whether that be to some other device, or a loop-back connection to
3661 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
3663 struct snd_soc_card
*card
= codec
->card
;
3664 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3665 struct snd_soc_dapm_widget
*w
;
3667 dev_dbg(codec
->dev
, "Auto NC: DAPMs: card:%p codec:%p\n",
3668 &card
->dapm
, &codec
->dapm
);
3670 list_for_each_entry(w
, &card
->widgets
, list
) {
3671 if (w
->dapm
!= dapm
)
3674 case snd_soc_dapm_input
:
3675 case snd_soc_dapm_output
:
3676 case snd_soc_dapm_micbias
:
3677 dev_dbg(codec
->dev
, "Auto NC: Checking widget %s\n",
3679 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
3681 "... Not in map; disabling\n");
3682 snd_soc_dapm_nc_pin(dapm
, w
->name
);
3692 * snd_soc_dapm_free - free dapm resources
3693 * @dapm: DAPM context
3695 * Free all dapm widgets and resources.
3697 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
3699 snd_soc_dapm_sys_remove(dapm
->dev
);
3700 dapm_debugfs_cleanup(dapm
);
3701 dapm_free_widgets(dapm
);
3702 list_del(&dapm
->list
);
3704 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
3706 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
3708 struct snd_soc_card
*card
= dapm
->card
;
3709 struct snd_soc_dapm_widget
*w
;
3710 LIST_HEAD(down_list
);
3713 mutex_lock(&card
->dapm_mutex
);
3715 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
3716 if (w
->dapm
!= dapm
)
3719 dapm_seq_insert(w
, &down_list
, false);
3725 /* If there were no widgets to power down we're already in
3729 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
3730 snd_soc_dapm_set_bias_level(dapm
,
3731 SND_SOC_BIAS_PREPARE
);
3732 dapm_seq_run(dapm
, &down_list
, 0, false);
3733 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
3734 snd_soc_dapm_set_bias_level(dapm
,
3735 SND_SOC_BIAS_STANDBY
);
3738 mutex_unlock(&card
->dapm_mutex
);
3742 * snd_soc_dapm_shutdown - callback for system shutdown
3744 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
3746 struct snd_soc_codec
*codec
;
3748 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
3749 soc_dapm_shutdown_codec(&codec
->dapm
);
3750 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
3751 snd_soc_dapm_set_bias_level(&codec
->dapm
,
3756 /* Module information */
3757 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3758 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3759 MODULE_LICENSE("GPL");