Full support for Ginger Console
[linux-ginger.git] / include / sound / soc-dapm.h
blobc1410e3191e3f6a43987efe818537a096401470e
1 /*
2 * linux/sound/soc-dapm.h -- ALSA SoC Dynamic Audio Power Management
4 * Author: Liam Girdwood
5 * Created: Aug 11th 2005
6 * Copyright: Wolfson Microelectronics. PLC.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #ifndef __LINUX_SND_SOC_DAPM_H
14 #define __LINUX_SND_SOC_DAPM_H
16 #include <linux/device.h>
17 #include <linux/types.h>
18 #include <sound/control.h>
19 #include <sound/soc.h>
21 /* widget has no PM register bit */
22 #define SND_SOC_NOPM -1
25 * SoC dynamic audio power management
27 * We can have upto 4 power domains
28 * 1. Codec domain - VREF, VMID
29 * Usually controlled at codec probe/remove, although can be set
30 * at stream time if power is not needed for sidetone, etc.
31 * 2. Platform/Machine domain - physically connected inputs and outputs
32 * Is platform/machine and user action specific, is set in the machine
33 * driver and by userspace e.g when HP are inserted
34 * 3. Path domain - Internal codec path mixers
35 * Are automatically set when mixer and mux settings are
36 * changed by the user.
37 * 4. Stream domain - DAC's and ADC's.
38 * Enabled when stream playback/capture is started.
41 /* codec domain */
42 #define SND_SOC_DAPM_VMID(wname) \
43 { .id = snd_soc_dapm_vmid, .name = wname, .kcontrols = NULL, \
44 .num_kcontrols = 0}
46 /* platform domain */
47 #define SND_SOC_DAPM_INPUT(wname) \
48 { .id = snd_soc_dapm_input, .name = wname, .kcontrols = NULL, \
49 .num_kcontrols = 0}
50 #define SND_SOC_DAPM_OUTPUT(wname) \
51 { .id = snd_soc_dapm_output, .name = wname, .kcontrols = NULL, \
52 .num_kcontrols = 0}
53 #define SND_SOC_DAPM_MIC(wname, wevent) \
54 { .id = snd_soc_dapm_mic, .name = wname, .kcontrols = NULL, \
55 .num_kcontrols = 0, .event = wevent, \
56 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
57 #define SND_SOC_DAPM_HP(wname, wevent) \
58 { .id = snd_soc_dapm_hp, .name = wname, .kcontrols = NULL, \
59 .num_kcontrols = 0, .event = wevent, \
60 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
61 #define SND_SOC_DAPM_SPK(wname, wevent) \
62 { .id = snd_soc_dapm_spk, .name = wname, .kcontrols = NULL, \
63 .num_kcontrols = 0, .event = wevent, \
64 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
65 #define SND_SOC_DAPM_LINE(wname, wevent) \
66 { .id = snd_soc_dapm_line, .name = wname, .kcontrols = NULL, \
67 .num_kcontrols = 0, .event = wevent, \
68 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
70 /* path domain */
71 #define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\
72 wcontrols, wncontrols) \
73 { .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
74 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
75 #define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
76 wcontrols, wncontrols)\
77 { .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
78 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
79 #define SND_SOC_DAPM_MIXER_NAMED_CTL(wname, wreg, wshift, winvert, \
80 wcontrols, wncontrols)\
81 { .id = snd_soc_dapm_mixer_named_ctl, .name = wname, .reg = wreg, \
82 .shift = wshift, .invert = winvert, .kcontrols = wcontrols, \
83 .num_kcontrols = wncontrols}
84 #define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
85 { .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
86 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0}
87 #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
88 { .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
89 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
90 #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
91 { .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
92 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
93 #define SND_SOC_DAPM_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \
94 { .id = snd_soc_dapm_value_mux, .name = wname, .reg = wreg, \
95 .shift = wshift, .invert = winvert, .kcontrols = wcontrols, \
96 .num_kcontrols = 1}
98 /* path domain with event - event handler must return 0 for success */
99 #define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
100 wncontrols, wevent, wflags) \
101 { .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
102 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
103 .event = wevent, .event_flags = wflags}
104 #define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
105 wncontrols, wevent, wflags) \
106 { .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
107 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
108 .event = wevent, .event_flags = wflags}
109 #define SND_SOC_DAPM_MIXER_NAMED_CTL_E(wname, wreg, wshift, winvert, \
110 wcontrols, wncontrols, wevent, wflags) \
111 { .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
112 .invert = winvert, .kcontrols = wcontrols, \
113 .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags}
114 #define SND_SOC_DAPM_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \
115 { .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
116 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0, \
117 .event = wevent, .event_flags = wflags}
118 #define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
119 wevent, wflags) \
120 { .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
121 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
122 .event = wevent, .event_flags = wflags}
123 #define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
124 wevent, wflags) \
125 { .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
126 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
127 .event = wevent, .event_flags = wflags}
129 /* events that are pre and post DAPM */
130 #define SND_SOC_DAPM_PRE(wname, wevent) \
131 { .id = snd_soc_dapm_pre, .name = wname, .kcontrols = NULL, \
132 .num_kcontrols = 0, .event = wevent, \
133 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
134 #define SND_SOC_DAPM_POST(wname, wevent) \
135 { .id = snd_soc_dapm_post, .name = wname, .kcontrols = NULL, \
136 .num_kcontrols = 0, .event = wevent, \
137 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
139 /* stream domain */
140 #define SND_SOC_DAPM_AIF_IN(wname, stname, wslot, wreg, wshift, winvert) \
141 { .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
142 .reg = wreg, .shift = wshift, .invert = winvert }
143 #define SND_SOC_DAPM_AIF_OUT(wname, stname, wslot, wreg, wshift, winvert) \
144 { .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
145 .reg = wreg, .shift = wshift, .invert = winvert }
146 #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
147 { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \
148 .shift = wshift, .invert = winvert}
149 #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \
150 wevent, wflags) \
151 { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \
152 .shift = wshift, .invert = winvert, \
153 .event = wevent, .event_flags = wflags}
154 #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
155 { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \
156 .shift = wshift, .invert = winvert}
157 #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \
158 wevent, wflags) \
159 { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \
160 .shift = wshift, .invert = winvert, \
161 .event = wevent, .event_flags = wflags}
163 /* generic widgets */
164 #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
165 { .id = wid, .name = wname, .kcontrols = NULL, .num_kcontrols = 0, \
166 .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \
167 .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \
168 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
169 #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \
170 { .id = snd_soc_dapm_supply, .name = wname, .reg = wreg, \
171 .shift = wshift, .invert = winvert, .event = wevent, \
172 .event_flags = wflags}
174 /* dapm kcontrol types */
175 #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
176 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
177 .info = snd_soc_info_volsw, \
178 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
179 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
180 #define SOC_DAPM_DOUBLE(xname, reg, shift_left, shift_right, max, invert, \
181 power) \
182 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
183 .info = snd_soc_info_volsw, \
184 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
185 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
186 ((max) << 16) | ((invert) << 24) }
187 #define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
188 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
189 .info = snd_soc_info_volsw, \
190 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
191 .tlv.p = (tlv_array), \
192 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
193 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
194 #define SOC_DAPM_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, \
195 power, tlv_array) \
196 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
197 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
198 .tlv.p = (tlv_array), \
199 .info = snd_soc_info_volsw, \
200 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
201 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
202 ((max) << 16) | ((invert) << 24) }
203 #define SOC_DAPM_ENUM(xname, xenum) \
204 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
205 .info = snd_soc_info_enum_double, \
206 .get = snd_soc_dapm_get_enum_double, \
207 .put = snd_soc_dapm_put_enum_double, \
208 .private_value = (unsigned long)&xenum }
209 #define SOC_DAPM_VALUE_ENUM(xname, xenum) \
210 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
211 .info = snd_soc_info_enum_double, \
212 .get = snd_soc_dapm_get_value_enum_double, \
213 .put = snd_soc_dapm_put_value_enum_double, \
214 .private_value = (unsigned long)&xenum }
215 #define SOC_DAPM_PIN_SWITCH(xname) \
216 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
217 .info = snd_soc_dapm_info_pin_switch, \
218 .get = snd_soc_dapm_get_pin_switch, \
219 .put = snd_soc_dapm_put_pin_switch, \
220 .private_value = (unsigned long)xname }
222 /* dapm stream operations */
223 #define SND_SOC_DAPM_STREAM_NOP 0x0
224 #define SND_SOC_DAPM_STREAM_START 0x1
225 #define SND_SOC_DAPM_STREAM_STOP 0x2
226 #define SND_SOC_DAPM_STREAM_SUSPEND 0x4
227 #define SND_SOC_DAPM_STREAM_RESUME 0x8
228 #define SND_SOC_DAPM_STREAM_PAUSE_PUSH 0x10
229 #define SND_SOC_DAPM_STREAM_PAUSE_RELEASE 0x20
231 /* dapm event types */
232 #define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
233 #define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
234 #define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
235 #define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
236 #define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
237 #define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
239 /* convenience event type detection */
240 #define SND_SOC_DAPM_EVENT_ON(e) \
241 (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
242 #define SND_SOC_DAPM_EVENT_OFF(e) \
243 (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
245 struct snd_soc_dapm_widget;
246 enum snd_soc_dapm_type;
247 struct snd_soc_dapm_path;
248 struct snd_soc_dapm_pin;
249 struct snd_soc_dapm_route;
251 int dapm_reg_event(struct snd_soc_dapm_widget *w,
252 struct snd_kcontrol *kcontrol, int event);
254 /* dapm controls */
255 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol);
257 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
258 struct snd_ctl_elem_value *ucontrol);
259 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
260 struct snd_ctl_elem_value *ucontrol);
261 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol);
263 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol);
265 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol);
267 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
268 struct snd_ctl_elem_info *uinfo);
269 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *uncontrol);
271 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *uncontrol);
273 int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
274 const struct snd_soc_dapm_widget *widget);
275 int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
276 const struct snd_soc_dapm_widget *widget,
277 int num);
279 /* dapm path setup */
280 int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec);
281 void snd_soc_dapm_free(struct snd_soc_device *socdev);
282 int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
283 const struct snd_soc_dapm_route *route, int num);
285 /* dapm events */
286 int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
287 int event);
288 void snd_soc_dapm_shutdown(struct snd_soc_device *socdev);
290 /* dapm sys fs - used by the core */
291 int snd_soc_dapm_sys_add(struct device *dev);
292 void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec);
294 /* dapm audio pin control and status */
295 int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin);
296 int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin);
297 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin);
298 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin);
299 int snd_soc_dapm_sync(struct snd_soc_codec *codec);
301 /* dapm widget types */
302 enum snd_soc_dapm_type {
303 snd_soc_dapm_input = 0, /* input pin */
304 snd_soc_dapm_output, /* output pin */
305 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
306 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */
307 snd_soc_dapm_mixer, /* mixes several analog signals together */
308 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
309 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
310 snd_soc_dapm_adc, /* analog to digital converter */
311 snd_soc_dapm_dac, /* digital to analog converter */
312 snd_soc_dapm_micbias, /* microphone bias (power) */
313 snd_soc_dapm_mic, /* microphone */
314 snd_soc_dapm_hp, /* headphones */
315 snd_soc_dapm_spk, /* speaker */
316 snd_soc_dapm_line, /* line input/output */
317 snd_soc_dapm_switch, /* analog switch */
318 snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */
319 snd_soc_dapm_pre, /* machine specific pre widget - exec first */
320 snd_soc_dapm_post, /* machine specific post widget - exec last */
321 snd_soc_dapm_supply, /* power/clock supply */
322 snd_soc_dapm_aif_in, /* audio interface input */
323 snd_soc_dapm_aif_out, /* audio interface output */
327 * DAPM audio route definition.
329 * Defines an audio route originating at source via control and finishing
330 * at sink.
332 struct snd_soc_dapm_route {
333 const char *sink;
334 const char *control;
335 const char *source;
338 /* dapm audio path between two widgets */
339 struct snd_soc_dapm_path {
340 char *name;
341 char *long_name;
343 /* source (input) and sink (output) widgets */
344 struct snd_soc_dapm_widget *source;
345 struct snd_soc_dapm_widget *sink;
346 struct snd_kcontrol *kcontrol;
348 /* status */
349 u32 connect:1; /* source and sink widgets are connected */
350 u32 walked:1; /* path has been walked */
352 struct list_head list_source;
353 struct list_head list_sink;
354 struct list_head list;
357 /* dapm widget */
358 struct snd_soc_dapm_widget {
359 enum snd_soc_dapm_type id;
360 char *name; /* widget name */
361 char *sname; /* stream name */
362 struct snd_soc_codec *codec;
363 struct list_head list;
365 /* dapm control */
366 short reg; /* negative reg = no direct dapm */
367 unsigned char shift; /* bits to shift */
368 unsigned int saved_value; /* widget saved value */
369 unsigned int value; /* widget current value */
370 unsigned int mask; /* non-shifted mask */
371 unsigned int on_val; /* on state value */
372 unsigned int off_val; /* off state value */
373 unsigned char power:1; /* block power status */
374 unsigned char invert:1; /* invert the power bit */
375 unsigned char active:1; /* active stream on DAC, ADC's */
376 unsigned char connected:1; /* connected codec pin */
377 unsigned char new:1; /* cnew complete */
378 unsigned char ext:1; /* has external widgets */
379 unsigned char muted:1; /* muted for pop reduction */
380 unsigned char suspend:1; /* was active before suspend */
381 unsigned char pmdown:1; /* waiting for timeout */
383 int (*power_check)(struct snd_soc_dapm_widget *w);
385 /* external events */
386 unsigned short event_flags; /* flags to specify event types */
387 int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
389 /* kcontrols that relate to this widget */
390 int num_kcontrols;
391 const struct snd_kcontrol_new *kcontrols;
393 /* widget input and outputs */
394 struct list_head sources;
395 struct list_head sinks;
397 /* used during DAPM updates */
398 struct list_head power_list;
401 #endif