xref: /linux/include/sound/soc-dapm.h (revision af0bc3ac9a9e830cb52b718ecb237c4e76a466be)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * linux/sound/soc-dapm.h -- ALSA SoC Dynamic Audio Power Management
4  *
5  * Author:	Liam Girdwood
6  * Created:	Aug 11th 2005
7  * Copyright:	Wolfson Microelectronics. PLC.
8  */
9 
10 #ifndef __LINUX_SND_SOC_DAPM_H
11 #define __LINUX_SND_SOC_DAPM_H
12 
13 #include <linux/types.h>
14 #include <sound/control.h>
15 #include <sound/soc-topology.h>
16 #include <sound/asoc.h>
17 
18 struct device;
19 struct regulator;
20 struct soc_enum;
21 struct snd_pcm_substream;
22 struct snd_soc_pcm_runtime;
23 struct snd_soc_dapm_context;
24 
25 /* widget has no PM register bit */
26 #define SND_SOC_NOPM	-1
27 
28 /*
29  * SoC dynamic audio power management
30  *
31  * We can have up to 4 power domains
32  *  1. Codec domain - VREF, VMID
33  *     Usually controlled at codec probe/remove, although can be set
34  *     at stream time if power is not needed for sidetone, etc.
35  *  2. Platform/Machine domain - physically connected inputs and outputs
36  *     Is platform/machine and user action specific, is set in the machine
37  *     driver and by userspace e.g when HP are inserted
38  *  3. Path domain - Internal codec path mixers
39  *     Are automatically set when mixer and mux settings are
40  *     changed by the user.
41  *  4. Stream domain - DAC's and ADC's.
42  *     Enabled when stream playback/capture is started.
43  */
44 
45 /* codec domain */
46 #define SND_SOC_DAPM_VMID(wname) \
47 (struct snd_soc_dapm_widget) { \
48 	.id = snd_soc_dapm_vmid, .name = wname, .kcontrol_news = NULL, \
49 	.num_kcontrols = 0}
50 
51 /* platform domain */
52 #define SND_SOC_DAPM_SIGGEN(wname) \
53 (struct snd_soc_dapm_widget) { \
54 	.id = snd_soc_dapm_siggen, .name = wname, .kcontrol_news = NULL, \
55 	.num_kcontrols = 0, .reg = SND_SOC_NOPM }
56 #define SND_SOC_DAPM_SINK(wname) \
57 (struct snd_soc_dapm_widget) { \
58 	.id = snd_soc_dapm_sink, .name = wname, .kcontrol_news = NULL, \
59 	.num_kcontrols = 0, .reg = SND_SOC_NOPM }
60 #define SND_SOC_DAPM_INPUT(wname) \
61 (struct snd_soc_dapm_widget) { \
62 	.id = snd_soc_dapm_input, .name = wname, .kcontrol_news = NULL, \
63 	.num_kcontrols = 0, .reg = SND_SOC_NOPM }
64 #define SND_SOC_DAPM_OUTPUT(wname) \
65 (struct snd_soc_dapm_widget) { \
66 	.id = snd_soc_dapm_output, .name = wname, .kcontrol_news = NULL, \
67 	.num_kcontrols = 0, .reg = SND_SOC_NOPM }
68 #define SND_SOC_DAPM_MIC(wname, wevent) \
69 (struct snd_soc_dapm_widget) { \
70 	.id = snd_soc_dapm_mic, .name = wname, .kcontrol_news = NULL, \
71 	.num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
72 	.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
73 #define SND_SOC_DAPM_HP(wname, wevent) \
74 (struct snd_soc_dapm_widget) { \
75 	.id = snd_soc_dapm_hp, .name = wname, .kcontrol_news = NULL, \
76 	.num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
77 	.event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
78 #define SND_SOC_DAPM_SPK(wname, wevent) \
79 (struct snd_soc_dapm_widget) { \
80 	.id = snd_soc_dapm_spk, .name = wname, .kcontrol_news = NULL, \
81 	.num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
82 	.event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
83 #define SND_SOC_DAPM_LINE(wname, wevent) \
84 (struct snd_soc_dapm_widget) { \
85 	.id = snd_soc_dapm_line, .name = wname, .kcontrol_news = NULL, \
86 	.num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
87 	.event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
88 
89 #define SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) \
90 	.reg = wreg, .mask = 1, .shift = wshift, \
91 	.on_val = winvert ? 0 : 1, .off_val = winvert ? 1 : 0
92 
93 /* path domain */
94 #define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\
95 	 wcontrols, wncontrols) \
96 (struct snd_soc_dapm_widget) { \
97 	.id = snd_soc_dapm_pga, .name = wname, \
98 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
99 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
100 #define SND_SOC_DAPM_OUT_DRV(wname, wreg, wshift, winvert,\
101 	 wcontrols, wncontrols) \
102 (struct snd_soc_dapm_widget) { \
103 	.id = snd_soc_dapm_out_drv, .name = wname, \
104 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
105 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
106 #define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
107 	 wcontrols, wncontrols)\
108 (struct snd_soc_dapm_widget) { \
109 	.id = snd_soc_dapm_mixer, .name = wname, \
110 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
111 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
112 #define SND_SOC_DAPM_MIXER_NAMED_CTL(wname, wreg, wshift, winvert, \
113 	 wcontrols, wncontrols)\
114 (struct snd_soc_dapm_widget) { \
115 	.id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
116 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
117 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
118 /* DEPRECATED: use SND_SOC_DAPM_SUPPLY */
119 #define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
120 (struct snd_soc_dapm_widget) { \
121 	.id = snd_soc_dapm_micbias, .name = wname, \
122 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
123 	.kcontrol_news = NULL, .num_kcontrols = 0}
124 #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
125 (struct snd_soc_dapm_widget) { \
126 	.id = snd_soc_dapm_switch, .name = wname, \
127 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
128 	.kcontrol_news = wcontrols, .num_kcontrols = 1}
129 #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
130 (struct snd_soc_dapm_widget) { \
131 	.id = snd_soc_dapm_mux, .name = wname, \
132 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
133 	.kcontrol_news = wcontrols, .num_kcontrols = 1}
134 #define SND_SOC_DAPM_DEMUX(wname, wreg, wshift, winvert, wcontrols) \
135 (struct snd_soc_dapm_widget) { \
136 	.id = snd_soc_dapm_demux, .name = wname, \
137 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
138 	.kcontrol_news = wcontrols, .num_kcontrols = 1}
139 
140 /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
141 #define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\
142 	 wcontrols) \
143 (struct snd_soc_dapm_widget) { \
144 	.id = snd_soc_dapm_pga, .name = wname, \
145 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
146 	.kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
147 #define SOC_MIXER_ARRAY(wname, wreg, wshift, winvert, \
148 	 wcontrols)\
149 (struct snd_soc_dapm_widget) { \
150 	.id = snd_soc_dapm_mixer, .name = wname, \
151 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
152 	.kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
153 #define SOC_MIXER_NAMED_CTL_ARRAY(wname, wreg, wshift, winvert, \
154 	 wcontrols)\
155 (struct snd_soc_dapm_widget) { \
156 	.id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
157 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
158 	.kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
159 
160 /* path domain with event - event handler must return 0 for success */
161 #define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
162 	wncontrols, wevent, wflags) \
163 (struct snd_soc_dapm_widget) { \
164 	.id = snd_soc_dapm_pga, .name = wname, \
165 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
166 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
167 	.event = wevent, .event_flags = wflags}
168 #define SND_SOC_DAPM_OUT_DRV_E(wname, wreg, wshift, winvert, wcontrols, \
169 	wncontrols, wevent, wflags) \
170 (struct snd_soc_dapm_widget) { \
171 	.id = snd_soc_dapm_out_drv, .name = wname, \
172 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
173 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
174 	.event = wevent, .event_flags = wflags}
175 #define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
176 	wncontrols, wevent, wflags) \
177 (struct snd_soc_dapm_widget) { \
178 	.id = snd_soc_dapm_mixer, .name = wname, \
179 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
180 	.kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
181 	.event = wevent, .event_flags = wflags}
182 #define SND_SOC_DAPM_MIXER_NAMED_CTL_E(wname, wreg, wshift, winvert, \
183 	wcontrols, wncontrols, wevent, wflags) \
184 (struct snd_soc_dapm_widget) { \
185 	.id = snd_soc_dapm_mixer, .name = wname, \
186 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
187 	.kcontrol_news = wcontrols, \
188 	.num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags}
189 #define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
190 	wevent, wflags) \
191 (struct snd_soc_dapm_widget) { \
192 	.id = snd_soc_dapm_switch, .name = wname, \
193 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
194 	.kcontrol_news = wcontrols, .num_kcontrols = 1, \
195 	.event = wevent, .event_flags = wflags}
196 #define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
197 	wevent, wflags) \
198 (struct snd_soc_dapm_widget) { \
199 	.id = snd_soc_dapm_mux, .name = wname, \
200 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
201 	.kcontrol_news = wcontrols, .num_kcontrols = 1, \
202 	.event = wevent, .event_flags = wflags}
203 
204 /* additional sequencing control within an event type */
205 #define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \
206 	wevent, wflags) \
207 (struct snd_soc_dapm_widget) { \
208 	.id = snd_soc_dapm_pga, .name = wname, \
209 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
210 	.event = wevent, .event_flags = wflags, \
211 	.subseq = wsubseq}
212 #define SND_SOC_DAPM_SUPPLY_S(wname, wsubseq, wreg, wshift, winvert, wevent, \
213 	wflags)	\
214 (struct snd_soc_dapm_widget) { \
215 	.id = snd_soc_dapm_supply, .name = wname, \
216 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
217 	.event = wevent, .event_flags = wflags, .subseq = wsubseq}
218 
219 /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
220 #define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
221 	wevent, wflags) \
222 (struct snd_soc_dapm_widget) { \
223 	.id = snd_soc_dapm_pga, .name = wname, \
224 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
225 	.kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
226 	.event = wevent, .event_flags = wflags}
227 #define SOC_MIXER_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
228 	wevent, wflags) \
229 (struct snd_soc_dapm_widget) { \
230 	.id = snd_soc_dapm_mixer, .name = wname, \
231 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
232 	.kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
233 	.event = wevent, .event_flags = wflags}
234 #define SOC_MIXER_NAMED_CTL_E_ARRAY(wname, wreg, wshift, winvert, \
235 	wcontrols, wevent, wflags) \
236 (struct snd_soc_dapm_widget) { \
237 	.id = snd_soc_dapm_mixer, .name = wname, \
238 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
239 	.kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
240 	.event = wevent, .event_flags = wflags}
241 
242 /* events that are pre and post DAPM */
243 #define SND_SOC_DAPM_PRE(wname, wevent) \
244 (struct snd_soc_dapm_widget) { \
245 	.id = snd_soc_dapm_pre, .name = wname, .kcontrol_news = NULL, \
246 	.num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
247 	.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
248 #define SND_SOC_DAPM_POST(wname, wevent) \
249 (struct snd_soc_dapm_widget) { \
250 	.id = snd_soc_dapm_post, .name = wname, .kcontrol_news = NULL, \
251 	.num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
252 	.event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
253 
254 /* stream domain */
255 #define SND_SOC_DAPM_AIF_IN(wname, stname, wchan, wreg, wshift, winvert) \
256 (struct snd_soc_dapm_widget) { \
257 	.id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
258 	.channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
259 #define SND_SOC_DAPM_AIF_IN_E(wname, stname, wchan, wreg, wshift, winvert, \
260 			      wevent, wflags)				\
261 (struct snd_soc_dapm_widget) { \
262 	.id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
263 	.channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
264 	.event = wevent, .event_flags = wflags }
265 #define SND_SOC_DAPM_AIF_OUT(wname, stname, wchan, wreg, wshift, winvert) \
266 (struct snd_soc_dapm_widget) { \
267 	.id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
268 	.channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
269 #define SND_SOC_DAPM_AIF_OUT_E(wname, stname, wchan, wreg, wshift, winvert, \
270 			     wevent, wflags)				\
271 (struct snd_soc_dapm_widget) { \
272 	.id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
273 	.channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
274 	.event = wevent, .event_flags = wflags }
275 #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
276 (struct snd_soc_dapm_widget) { \
277 	.id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
278 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) }
279 #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \
280 			   wevent, wflags)				\
281 (struct snd_soc_dapm_widget) { \
282 	.id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
283 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
284 	.event = wevent, .event_flags = wflags}
285 
286 #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
287 (struct snd_soc_dapm_widget) { \
288 	.id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
289 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
290 #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \
291 			   wevent, wflags)				\
292 (struct snd_soc_dapm_widget) { \
293 	.id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
294 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
295 	.event = wevent, .event_flags = wflags}
296 #define SND_SOC_DAPM_CLOCK_SUPPLY(wname) \
297 (struct snd_soc_dapm_widget) { \
298 	.id = snd_soc_dapm_clock_supply, .name = wname, \
299 	.reg = SND_SOC_NOPM, .event = snd_soc_dapm_clock_event, \
300 	.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
301 
302 /* generic widgets */
303 #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
304 (struct snd_soc_dapm_widget) { \
305 	.id = wid, .name = wname, .kcontrol_news = NULL, .num_kcontrols = 0, \
306 	.reg = wreg, .shift = wshift, .mask = wmask, \
307 	.on_val = won_val, .off_val = woff_val, }
308 #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \
309 (struct snd_soc_dapm_widget) { \
310 	.id = snd_soc_dapm_supply, .name = wname, \
311 	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
312 	.event = wevent, .event_flags = wflags}
313 #define SND_SOC_DAPM_REGULATOR_SUPPLY(wname, wdelay, wflags)	    \
314 (struct snd_soc_dapm_widget) { \
315 	.id = snd_soc_dapm_regulator_supply, .name = wname, \
316 	.reg = SND_SOC_NOPM, .shift = wdelay, .event = snd_soc_dapm_regulator_event, \
317 	.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
318 	.on_val = wflags}
319 #define SND_SOC_DAPM_PINCTRL(wname, active, sleep) \
320 (struct snd_soc_dapm_widget) { \
321 	.id = snd_soc_dapm_pinctrl, .name = wname, \
322 	.priv = (&(struct snd_soc_dapm_pinctrl_priv) \
323 		{ .active_state = active, .sleep_state = sleep,}), \
324 	.reg = SND_SOC_NOPM, .event = snd_soc_dapm_pinctrl_event, \
325 	.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
326 
327 
328 
329 /* dapm kcontrol types */
330 #define SOC_DAPM_DOUBLE(xname, reg, lshift, rshift, max, invert) \
331 	SOC_DOUBLE_EXT(xname, reg, lshift, rshift, max, invert, \
332 		       snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw)
333 #define SOC_DAPM_DOUBLE_R(xname, lreg, rreg, shift, max, invert) \
334 	SOC_DOUBLE_R_EXT(xname, lreg, rreg, shift, max, invert, \
335 			 snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw)
336 #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
337 	SOC_SINGLE_EXT(xname, reg, shift, max, invert, \
338 		       snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw)
339 #define SOC_DAPM_SINGLE_VIRT(xname, max) \
340 	SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0)
341 #define SOC_DAPM_DOUBLE_R_TLV(xname, lreg, rreg, shift, max, invert, tlv_array) \
342 	SOC_DOUBLE_R_EXT_TLV(xname, lreg, rreg, shift, max, invert, \
343 			     snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw, \
344 			     tlv_array)
345 #define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
346 	SOC_SINGLE_EXT_TLV(xname, reg, shift, max, invert, \
347 			   snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw, \
348 			   tlv_array)
349 #define SOC_DAPM_SINGLE_TLV_VIRT(xname, max, tlv_array) \
350 	SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0, tlv_array)
351 #define SOC_DAPM_ENUM(xname, xenum) \
352 	SOC_ENUM_EXT(xname, xenum, snd_soc_dapm_get_enum_double, \
353 		     snd_soc_dapm_put_enum_double)
354 #define SOC_DAPM_ENUM_EXT(xname, xenum, xget, xput) \
355 	SOC_ENUM_EXT(xname, xenum, xget, xput)
356 
357 #define SOC_DAPM_SINGLE_AUTODISABLE(xname, reg, shift, max, invert) \
358 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
359 	.info = snd_soc_info_volsw, \
360 	.get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
361 	.private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 1) }
362 #define SOC_DAPM_SINGLE_TLV_AUTODISABLE(xname, reg, shift, max, invert, tlv_array) \
363 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
364 	.info = snd_soc_info_volsw, \
365 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
366 	.tlv.p = (tlv_array), \
367 	.get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
368 	.private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 1) }
369 #define SOC_DAPM_PIN_SWITCH(xname) \
370 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
371 	.info = snd_soc_dapm_info_pin_switch, \
372 	.get = snd_soc_dapm_get_pin_switch, \
373 	.put = snd_soc_dapm_put_pin_switch, \
374 	.private_value = (unsigned long)xname }
375 
376 /* dapm stream operations */
377 #define SND_SOC_DAPM_STREAM_NOP			0x0
378 #define SND_SOC_DAPM_STREAM_START		0x1
379 #define SND_SOC_DAPM_STREAM_STOP		0x2
380 #define SND_SOC_DAPM_STREAM_SUSPEND		0x4
381 #define SND_SOC_DAPM_STREAM_RESUME		0x8
382 #define SND_SOC_DAPM_STREAM_PAUSE_PUSH		0x10
383 #define SND_SOC_DAPM_STREAM_PAUSE_RELEASE	0x20
384 
385 /* dapm event types */
386 #define SND_SOC_DAPM_PRE_PMU		0x1	/* before widget power up */
387 #define SND_SOC_DAPM_POST_PMU		0x2	/* after  widget power up */
388 #define SND_SOC_DAPM_PRE_PMD		0x4	/* before widget power down */
389 #define SND_SOC_DAPM_POST_PMD		0x8	/* after  widget power down */
390 #define SND_SOC_DAPM_PRE_REG		0x10	/* before audio path setup */
391 #define SND_SOC_DAPM_POST_REG		0x20	/* after  audio path setup */
392 #define SND_SOC_DAPM_WILL_PMU		0x40	/* called at start of sequence */
393 #define SND_SOC_DAPM_WILL_PMD		0x80	/* called at start of sequence */
394 #define SND_SOC_DAPM_PRE_POST_PMD	(SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD)
395 #define SND_SOC_DAPM_PRE_POST_PMU	(SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU)
396 
397 /* convenience event type detection */
398 #define SND_SOC_DAPM_EVENT_ON(e)	(e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
399 #define SND_SOC_DAPM_EVENT_OFF(e)	(e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
400 
401 /* regulator widget flags */
402 #define SND_SOC_DAPM_REGULATOR_BYPASS	0x1	/* bypass when disabled */
403 
404 /*
405  * Bias levels
406  *
407  * @ON:      Bias is fully on for audio playback and capture operations.
408  * @PREPARE: Prepare for audio operations. Called before DAPM switching for
409  *           stream start and stop operations.
410  * @STANDBY: Low power standby state when no playback/capture operations are
411  *           in progress. NOTE: The transition time between STANDBY and ON
412  *           should be as fast as possible and no longer than 10ms.
413  * @OFF:     Power Off. No restrictions on transition times.
414  */
415 enum snd_soc_bias_level {
416 	SND_SOC_BIAS_OFF = 0,
417 	SND_SOC_BIAS_STANDBY = 1,
418 	SND_SOC_BIAS_PREPARE = 2,
419 	SND_SOC_BIAS_ON = 3,
420 };
421 
422 /* dapm widget types */
423 enum snd_soc_dapm_type {
424 	snd_soc_dapm_input = 0,		/* input pin */
425 	snd_soc_dapm_output,		/* output pin */
426 	snd_soc_dapm_mux,		/* selects 1 analog signal from many inputs */
427 	snd_soc_dapm_demux,		/* connects the input to one of multiple outputs */
428 	snd_soc_dapm_mixer,		/* mixes several analog signals together */
429 	snd_soc_dapm_mixer_named_ctl,	/* mixer with named controls */
430 	snd_soc_dapm_pga,		/* programmable gain/attenuation (volume) */
431 	snd_soc_dapm_out_drv,		/* output driver */
432 	snd_soc_dapm_adc,		/* analog to digital converter */
433 	snd_soc_dapm_dac,		/* digital to analog converter */
434 	snd_soc_dapm_micbias,		/* microphone bias (power) - DEPRECATED: use snd_soc_dapm_supply */
435 	snd_soc_dapm_mic,		/* microphone */
436 	snd_soc_dapm_hp,		/* headphones */
437 	snd_soc_dapm_spk,		/* speaker */
438 	snd_soc_dapm_line,		/* line input/output */
439 	snd_soc_dapm_switch,		/* analog switch */
440 	snd_soc_dapm_vmid,		/* codec bias/vmid - to minimise pops */
441 	snd_soc_dapm_pre,		/* machine specific pre widget - exec first */
442 	snd_soc_dapm_post,		/* machine specific post widget - exec last */
443 	snd_soc_dapm_supply,		/* power/clock supply */
444 	snd_soc_dapm_pinctrl,		/* pinctrl */
445 	snd_soc_dapm_regulator_supply,	/* external regulator */
446 	snd_soc_dapm_clock_supply,	/* external clock */
447 	snd_soc_dapm_aif_in,		/* audio interface input */
448 	snd_soc_dapm_aif_out,		/* audio interface output */
449 	snd_soc_dapm_siggen,		/* signal generator */
450 	snd_soc_dapm_sink,
451 	snd_soc_dapm_dai_in,		/* link to DAI structure */
452 	snd_soc_dapm_dai_out,
453 	snd_soc_dapm_dai_link,		/* link between two DAI structures */
454 	snd_soc_dapm_kcontrol,		/* Auto-disabled kcontrol */
455 	snd_soc_dapm_buffer,		/* DSP/CODEC internal buffer */
456 	snd_soc_dapm_scheduler,		/* DSP/CODEC internal scheduler */
457 	snd_soc_dapm_effect,		/* DSP/CODEC effect component */
458 	snd_soc_dapm_src,		/* DSP/CODEC SRC component */
459 	snd_soc_dapm_asrc,		/* DSP/CODEC ASRC component */
460 	snd_soc_dapm_encoder,		/* FW/SW audio encoder component */
461 	snd_soc_dapm_decoder,		/* FW/SW audio decoder component */
462 
463 	/* Don't edit below this line */
464 	SND_SOC_DAPM_TYPE_COUNT
465 };
466 
467 /*
468  * DAPM audio route definition.
469  *
470  * Defines an audio route originating at source via control and finishing
471  * at sink.
472  */
473 struct snd_soc_dapm_route {
474 	const char *sink;
475 	const char *control;
476 	const char *source;
477 
478 	/* Note: currently only supported for links where source is a supply */
479 	int (*connected)(struct snd_soc_dapm_widget *source,
480 			 struct snd_soc_dapm_widget *sink);
481 
482 	struct snd_soc_dobj dobj;
483 };
484 
485 /* dapm audio path between two widgets */
486 struct snd_soc_dapm_path {
487 	const char *name;
488 
489 	/*
490 	 * source (input) and sink (output) widgets
491 	 * The union is for convience, since it is a lot nicer to type
492 	 * p->source, rather than p->node[SND_SOC_DAPM_DIR_IN]
493 	 */
494 	union {
495 		struct {
496 			struct snd_soc_dapm_widget *source;
497 			struct snd_soc_dapm_widget *sink;
498 		};
499 		struct snd_soc_dapm_widget *node[2];
500 	};
501 
502 	/* status */
503 	u32 connect:1;		/* source and sink widgets are connected */
504 	u32 walking:1;		/* path is in the process of being walked */
505 	u32 is_supply:1;	/* At least one of the connected widgets is a supply */
506 
507 	int (*connected)(struct snd_soc_dapm_widget *source,
508 			 struct snd_soc_dapm_widget *sink);
509 
510 	struct list_head list_node[2];
511 	struct list_head list_kcontrol;
512 	struct list_head list;
513 };
514 
515 /* dapm widget */
516 struct snd_soc_dapm_widget {
517 	enum snd_soc_dapm_type id;
518 	const char *name;			/* widget name */
519 	const char *sname;			/* stream name */
520 	struct list_head list;
521 	struct snd_soc_dapm_context *dapm;
522 
523 	void *priv;				/* widget specific data */
524 	struct regulator *regulator;		/* attached regulator */
525 	struct pinctrl *pinctrl;		/* attached pinctrl */
526 
527 	/* dapm control */
528 	int reg;				/* negative reg = no direct dapm */
529 	unsigned char shift;			/* bits to shift */
530 	unsigned int mask;			/* non-shifted mask */
531 	unsigned int on_val;			/* on state value */
532 	unsigned int off_val;			/* off state value */
533 	unsigned char power:1;			/* block power status */
534 	unsigned char active:1;			/* active stream on DAC, ADC's */
535 	unsigned char connected:1;		/* connected codec pin */
536 	unsigned char new:1;			/* cnew complete */
537 	unsigned char force:1;			/* force state */
538 	unsigned char ignore_suspend:1;		/* kept enabled over suspend */
539 	unsigned char new_power:1;		/* power from this run */
540 	unsigned char power_checked:1;		/* power checked this run */
541 	unsigned char is_supply:1;		/* Widget is a supply type widget */
542 	unsigned char is_ep:2;			/* Widget is a endpoint type widget */
543 	unsigned char no_wname_in_kcontrol_name:1; /* No widget name prefix in kcontrol name */
544 	int subseq;				/* sort within widget type */
545 
546 	int (*power_check)(struct snd_soc_dapm_widget *w);
547 
548 	/* external events */
549 	unsigned short event_flags;		/* flags to specify event types */
550 	int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
551 
552 	/* kcontrols that relate to this widget */
553 	int num_kcontrols;
554 	const struct snd_kcontrol_new *kcontrol_news;
555 	struct snd_kcontrol **kcontrols;
556 	struct snd_soc_dobj dobj;
557 
558 	/* widget input and output edges */
559 	struct list_head edges[2];
560 
561 	/* used during DAPM updates */
562 	struct list_head work_list;
563 	struct list_head power_list;
564 	struct list_head dirty;
565 	int endpoints[2];
566 
567 	struct clk *clk;
568 
569 	int channel;
570 };
571 
572 struct snd_soc_dapm_update {
573 	struct snd_kcontrol *kcontrol;
574 	int reg;
575 	int mask;
576 	int val;
577 	int reg2;
578 	int mask2;
579 	int val2;
580 	bool has_second_set;
581 };
582 
583 /* A list of widgets associated with an object, typically a snd_kcontrol */
584 struct snd_soc_dapm_widget_list {
585 	int num_widgets;
586 	struct snd_soc_dapm_widget *widgets[] __counted_by(num_widgets);
587 };
588 
589 struct snd_soc_dapm_stats {
590 	int power_checks;
591 	int path_checks;
592 	int neighbour_checks;
593 };
594 
595 struct snd_soc_dapm_pinctrl_priv {
596 	const char *active_state;
597 	const char *sleep_state;
598 };
599 
600 enum snd_soc_dapm_direction {
601 	SND_SOC_DAPM_DIR_IN,
602 	SND_SOC_DAPM_DIR_OUT
603 };
604 
605 #define SND_SOC_DAPM_DIR_TO_EP(x) BIT(x)
606 
607 #define SND_SOC_DAPM_EP_SOURCE	SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_IN)
608 #define SND_SOC_DAPM_EP_SINK	SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_OUT)
609 
610 struct snd_soc_dapm_context *snd_soc_dapm_alloc(struct device *dev);
611 
612 int snd_soc_dapm_regulator_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event);
613 int snd_soc_dapm_clock_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event);
614 int snd_soc_dapm_pinctrl_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event);
615 
616 /* dapm controls */
617 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
618 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
619 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
620 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
621 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo);
622 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uncontrol);
623 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uncontrol);
624 int snd_soc_dapm_get_component_pin_switch(struct snd_kcontrol *kcontrol,
625 					  struct snd_ctl_elem_value *uncontrol);
626 int snd_soc_dapm_put_component_pin_switch(struct snd_kcontrol *kcontrol,
627 					  struct snd_ctl_elem_value *uncontrol);
628 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
629 	const struct snd_soc_dapm_widget *widget, unsigned int num);
630 struct snd_soc_dapm_widget *snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
631 		const struct snd_soc_dapm_widget *widget);
632 struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
633 		const struct snd_soc_dapm_widget *widget);
634 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, struct snd_soc_dai *dai);
635 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
636 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
637 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
638 
639 int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
640 			    struct snd_pcm_hw_params *params, struct snd_soc_dai *dai);
641 int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s);
642 struct device *snd_soc_dapm_to_dev(struct snd_soc_dapm_context *dapm);
643 struct snd_soc_card *snd_soc_dapm_to_card(struct snd_soc_dapm_context *dapm);
644 struct snd_soc_component *snd_soc_dapm_to_component(struct snd_soc_dapm_context *dapm);
645 
646 bool snd_soc_dapm_get_idle_bias(struct snd_soc_dapm_context *dapm);
647 void snd_soc_dapm_set_idle_bias(struct snd_soc_dapm_context *dapm, bool on);
648 
649 /* dapm path setup */
650 int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
651 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm);
652 void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm,
653 		       struct snd_soc_card *card, struct snd_soc_component *component);
654 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
655 			    const struct snd_soc_dapm_route *route, int num);
656 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
657 			    const struct snd_soc_dapm_route *route, int num);
658 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
659 
660 /* dapm events */
661 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int event);
662 void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream);
663 void snd_soc_dapm_shutdown(struct snd_soc_card *card);
664 
665 /* external DAPM widget events */
666 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
667 		struct snd_kcontrol *kcontrol, int connect, struct snd_soc_dapm_update *update);
668 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm,
669 		struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e,
670 		struct snd_soc_dapm_update *update);
671 
672 /* dapm sys fs - used by the core */
673 extern struct attribute *snd_soc_dapm_dev_attrs[];
674 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, struct dentry *parent);
675 
676 /* dapm audio pin control and status */
677 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin);
678 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm, const char *pin);
679 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, const char *pin);
680 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm, const char *pin);
681 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, const char *pin);
682 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
683 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm);
684 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin);
685 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm, const char *pin);
686 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, const char *pin);
687 void snd_soc_dapm_mark_endpoints_dirty(struct snd_soc_card *card);
688 
689 /* dapm path query */
690 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
691 	struct snd_soc_dapm_widget_list **list,
692 	bool (*custom_stop_condition)(struct snd_soc_dapm_widget *, enum snd_soc_dapm_direction));
693 void snd_soc_dapm_dai_free_widgets(struct snd_soc_dapm_widget_list **list);
694 
695 struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_to_dapm(struct snd_kcontrol *kcontrol);
696 struct snd_soc_dapm_widget *snd_soc_dapm_kcontrol_to_widget(struct snd_kcontrol *kcontrol);
697 struct snd_soc_component *snd_soc_dapm_kcontrol_to_component(struct snd_kcontrol *kcontrol);
698 unsigned int snd_soc_dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol);
699 
700 int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level);
701 enum snd_soc_bias_level snd_soc_dapm_get_bias_level(struct snd_soc_dapm_context *dapm);
702 void snd_soc_dapm_init_bias_level(struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level);
703 
704 #define for_each_dapm_widgets(list, i, widget)				\
705 	for ((i) = 0;							\
706 	     (i) < list->num_widgets && (widget = list->widgets[i]);	\
707 	     (i)++)
708 
709 /**
710  * snd_soc_dapm_widget_for_each_path - Iterates over all paths in the
711  *   specified direction of a widget
712  * @w: The widget
713  * @dir: Whether to iterate over the paths where the specified widget is the
714  *       incoming or outgoing widgets
715  * @p: The path iterator variable
716  */
717 #define snd_soc_dapm_widget_for_each_path(w, dir, p) \
718 	list_for_each_entry(p, &w->edges[dir], list_node[dir])
719 
720 /**
721  * snd_soc_dapm_widget_for_each_path_safe - Iterates over all paths in the
722  *   specified direction of a widget
723  * @w: The widget
724  * @dir: Whether to iterate over the paths where the specified widget is the
725  *       incoming or outgoing widgets
726  * @p: The path iterator variable
727  * @next_p: Temporary storage for the next path
728  *
729  *  This function works like snd_soc_dapm_widget_for_each_path, expect that
730  *  it is safe to remove the current path from the list while iterating
731  */
732 #define snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p) \
733 	list_for_each_entry_safe(p, next_p, &w->edges[dir], list_node[dir])
734 
735 /**
736  * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths leaving a
737  *  widget
738  * @w: The widget
739  * @p: The path iterator variable
740  */
741 #define snd_soc_dapm_widget_for_each_sink_path(w, p) \
742 	snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_IN, p)
743 
744 /**
745  * snd_soc_dapm_widget_for_each_source_path - Iterates over all paths leading to
746  *  a widget
747  * @w: The widget
748  * @p: The path iterator variable
749  */
750 #define snd_soc_dapm_widget_for_each_source_path(w, p) \
751 	snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_OUT, p)
752 
753 #endif
754