Bug fixes
[cbs-scheduler.git] / include / sound / soc-dapm.h
blobdfa804958820d631f52422f55ff2390e477eea9b
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_MICBIAS(wname, wreg, wshift, winvert) \
80 { .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
81 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0}
82 #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
83 { .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
84 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
85 #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
86 { .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
87 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
88 #define SND_SOC_DAPM_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \
89 { .id = snd_soc_dapm_value_mux, .name = wname, .reg = wreg, \
90 .shift = wshift, .invert = winvert, .kcontrols = wcontrols, \
91 .num_kcontrols = 1}
93 /* path domain with event - event handler must return 0 for success */
94 #define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
95 wncontrols, wevent, wflags) \
96 { .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
97 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
98 .event = wevent, .event_flags = wflags}
99 #define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
100 wncontrols, wevent, wflags) \
101 { .id = snd_soc_dapm_mixer, .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_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \
105 { .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
106 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0, \
107 .event = wevent, .event_flags = wflags}
108 #define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
109 wevent, wflags) \
110 { .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
111 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
112 .event = wevent, .event_flags = wflags}
113 #define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
114 wevent, wflags) \
115 { .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
116 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
117 .event = wevent, .event_flags = wflags}
119 /* events that are pre and post DAPM */
120 #define SND_SOC_DAPM_PRE(wname, wevent) \
121 { .id = snd_soc_dapm_pre, .name = wname, .kcontrols = NULL, \
122 .num_kcontrols = 0, .event = wevent, \
123 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
124 #define SND_SOC_DAPM_POST(wname, wevent) \
125 { .id = snd_soc_dapm_post, .name = wname, .kcontrols = NULL, \
126 .num_kcontrols = 0, .event = wevent, \
127 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
129 /* stream domain */
130 #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
131 { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \
132 .shift = wshift, .invert = winvert}
133 #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
134 { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \
135 .shift = wshift, .invert = winvert}
137 /* generic register modifier widget */
138 #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
139 { .id = wid, .name = wname, .kcontrols = NULL, .num_kcontrols = 0, \
140 .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \
141 .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \
142 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
144 /* dapm kcontrol types */
145 #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
146 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
147 .info = snd_soc_info_volsw, \
148 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
149 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
150 #define SOC_DAPM_DOUBLE(xname, reg, shift_left, shift_right, max, invert, \
151 power) \
152 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
153 .info = snd_soc_info_volsw, \
154 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
155 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
156 ((max) << 16) | ((invert) << 24) }
157 #define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
158 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
159 .info = snd_soc_info_volsw, \
160 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
161 .tlv.p = (tlv_array), \
162 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
163 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
164 #define SOC_DAPM_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, \
165 power, tlv_array) \
166 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
167 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
168 .tlv.p = (tlv_array), \
169 .info = snd_soc_info_volsw, \
170 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
171 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
172 ((max) << 16) | ((invert) << 24) }
173 #define SOC_DAPM_ENUM(xname, xenum) \
174 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
175 .info = snd_soc_info_enum_double, \
176 .get = snd_soc_dapm_get_enum_double, \
177 .put = snd_soc_dapm_put_enum_double, \
178 .private_value = (unsigned long)&xenum }
179 #define SOC_DAPM_VALUE_ENUM(xname, xenum) \
180 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
181 .info = snd_soc_info_enum_double, \
182 .get = snd_soc_dapm_get_value_enum_double, \
183 .put = snd_soc_dapm_put_value_enum_double, \
184 .private_value = (unsigned long)&xenum }
186 /* dapm stream operations */
187 #define SND_SOC_DAPM_STREAM_NOP 0x0
188 #define SND_SOC_DAPM_STREAM_START 0x1
189 #define SND_SOC_DAPM_STREAM_STOP 0x2
190 #define SND_SOC_DAPM_STREAM_SUSPEND 0x4
191 #define SND_SOC_DAPM_STREAM_RESUME 0x8
192 #define SND_SOC_DAPM_STREAM_PAUSE_PUSH 0x10
193 #define SND_SOC_DAPM_STREAM_PAUSE_RELEASE 0x20
195 /* dapm event types */
196 #define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
197 #define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
198 #define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
199 #define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
200 #define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
201 #define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
203 /* convenience event type detection */
204 #define SND_SOC_DAPM_EVENT_ON(e) \
205 (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
206 #define SND_SOC_DAPM_EVENT_OFF(e) \
207 (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
209 struct snd_soc_dapm_widget;
210 enum snd_soc_dapm_type;
211 struct snd_soc_dapm_path;
212 struct snd_soc_dapm_pin;
213 struct snd_soc_dapm_route;
215 int dapm_reg_event(struct snd_soc_dapm_widget *w,
216 struct snd_kcontrol *kcontrol, int event);
218 /* dapm controls */
219 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_value *ucontrol);
221 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
222 struct snd_ctl_elem_value *ucontrol);
223 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
224 struct snd_ctl_elem_value *ucontrol);
225 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_value *ucontrol);
227 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol);
229 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol);
231 int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
232 const struct snd_soc_dapm_widget *widget);
233 int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
234 const struct snd_soc_dapm_widget *widget,
235 int num);
237 /* dapm path setup */
238 int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec);
239 void snd_soc_dapm_free(struct snd_soc_device *socdev);
240 int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
241 const struct snd_soc_dapm_route *route, int num);
243 /* dapm events */
244 int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
245 int event);
246 int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
247 enum snd_soc_bias_level level);
249 /* dapm sys fs - used by the core */
250 int snd_soc_dapm_sys_add(struct device *dev);
252 /* dapm audio pin control and status */
253 int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin);
254 int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin);
255 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, char *pin);
256 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin);
257 int snd_soc_dapm_sync(struct snd_soc_codec *codec);
259 /* dapm widget types */
260 enum snd_soc_dapm_type {
261 snd_soc_dapm_input = 0, /* input pin */
262 snd_soc_dapm_output, /* output pin */
263 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
264 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */
265 snd_soc_dapm_mixer, /* mixes several analog signals together */
266 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
267 snd_soc_dapm_adc, /* analog to digital converter */
268 snd_soc_dapm_dac, /* digital to analog converter */
269 snd_soc_dapm_micbias, /* microphone bias (power) */
270 snd_soc_dapm_mic, /* microphone */
271 snd_soc_dapm_hp, /* headphones */
272 snd_soc_dapm_spk, /* speaker */
273 snd_soc_dapm_line, /* line input/output */
274 snd_soc_dapm_switch, /* analog switch */
275 snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */
276 snd_soc_dapm_pre, /* machine specific pre widget - exec first */
277 snd_soc_dapm_post, /* machine specific post widget - exec last */
281 * DAPM audio route definition.
283 * Defines an audio route originating at source via control and finishing
284 * at sink.
286 struct snd_soc_dapm_route {
287 const char *sink;
288 const char *control;
289 const char *source;
292 /* dapm audio path between two widgets */
293 struct snd_soc_dapm_path {
294 char *name;
295 char *long_name;
297 /* source (input) and sink (output) widgets */
298 struct snd_soc_dapm_widget *source;
299 struct snd_soc_dapm_widget *sink;
300 struct snd_kcontrol *kcontrol;
302 /* status */
303 u32 connect:1; /* source and sink widgets are connected */
304 u32 walked:1; /* path has been walked */
306 struct list_head list_source;
307 struct list_head list_sink;
308 struct list_head list;
311 /* dapm widget */
312 struct snd_soc_dapm_widget {
313 enum snd_soc_dapm_type id;
314 char *name; /* widget name */
315 char *sname; /* stream name */
316 struct snd_soc_codec *codec;
317 struct list_head list;
319 /* dapm control */
320 short reg; /* negative reg = no direct dapm */
321 unsigned char shift; /* bits to shift */
322 unsigned int saved_value; /* widget saved value */
323 unsigned int value; /* widget current value */
324 unsigned int mask; /* non-shifted mask */
325 unsigned int on_val; /* on state value */
326 unsigned int off_val; /* off state value */
327 unsigned char power:1; /* block power status */
328 unsigned char invert:1; /* invert the power bit */
329 unsigned char active:1; /* active stream on DAC, ADC's */
330 unsigned char connected:1; /* connected codec pin */
331 unsigned char new:1; /* cnew complete */
332 unsigned char ext:1; /* has external widgets */
333 unsigned char muted:1; /* muted for pop reduction */
334 unsigned char suspend:1; /* was active before suspend */
335 unsigned char pmdown:1; /* waiting for timeout */
337 /* external events */
338 unsigned short event_flags; /* flags to specify event types */
339 int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
341 /* kcontrols that relate to this widget */
342 int num_kcontrols;
343 const struct snd_kcontrol_new *kcontrols;
345 /* widget input and outputs */
346 struct list_head sources;
347 struct list_head sinks;
350 #endif