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