blob: c1b26fcc0b5c81e8950c77230675bf9314b2c2a8 [file] [log] [blame]
Richard Purdie808db4a2006-10-06 18:20:14 +02001/*
2 * linux/sound/soc-dapm.h -- ALSA SoC Dynamic Audio Power Management
3 *
4 * Author: Liam Girdwood
5 * Created: Aug 11th 2005
6 * Copyright: Wolfson Microelectronics. PLC.
7 *
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.
11 */
12
13#ifndef __LINUX_SND_SOC_DAPM_H
14#define __LINUX_SND_SOC_DAPM_H
15
16#include <linux/device.h>
17#include <linux/types.h>
18#include <sound/control.h>
19#include <sound/soc.h>
20
21/* widget has no PM register bit */
22#define SND_SOC_NOPM -1
23
24/*
Joe Perchesb7d2a802007-12-18 13:14:21 +010025 * SoC dynamic audio power management
Richard Purdie808db4a2006-10-06 18:20:14 +020026 *
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.
39 */
40
41/* codec domain */
42#define SND_SOC_DAPM_VMID(wname) \
43{ .id = snd_soc_dapm_vmid, .name = wname, .kcontrols = NULL, \
44 .num_kcontrols = 0}
45
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}
69
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
89/* path domain with event - event handler must return 0 for success */
90#define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
91 wncontrols, wevent, wflags) \
92{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
93 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
94 .event = wevent, .event_flags = wflags}
95#define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
96 wncontrols, wevent, wflags) \
97{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
98 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
99 .event = wevent, .event_flags = wflags}
100#define SND_SOC_DAPM_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \
101{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
102 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0, \
103 .event = wevent, .event_flags = wflags}
104#define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
105 wevent, wflags) \
106{ .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
107 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1 \
108 .event = wevent, .event_flags = wflags}
109#define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
110 wevent, wflags) \
111{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
112 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
113 .event = wevent, .event_flags = wflags}
114
115/* events that are pre and post DAPM */
116#define SND_SOC_DAPM_PRE(wname, wevent) \
117{ .id = snd_soc_dapm_pre, .name = wname, .kcontrols = NULL, \
118 .num_kcontrols = 0, .event = wevent, \
119 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
120#define SND_SOC_DAPM_POST(wname, wevent) \
121{ .id = snd_soc_dapm_post, .name = wname, .kcontrols = NULL, \
122 .num_kcontrols = 0, .event = wevent, \
123 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
124
125/* stream domain */
126#define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
127{ .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \
128 .shift = wshift, .invert = winvert}
129#define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
130{ .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \
131 .shift = wshift, .invert = winvert}
132
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300133/* generic register modifier widget */
134#define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
135{ .id = wid, .name = wname, .kcontrols = NULL, .num_kcontrols = 0, \
136 .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \
137 .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \
138 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
139
Richard Purdie808db4a2006-10-06 18:20:14 +0200140/* dapm kcontrol types */
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100141#define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
Richard Purdie808db4a2006-10-06 18:20:14 +0200142{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
143 .info = snd_soc_info_volsw, \
144 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100145 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
146#define SOC_DAPM_DOUBLE(xname, reg, shift_left, shift_right, max, invert, \
Richard Purdie808db4a2006-10-06 18:20:14 +0200147 power) \
148{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
149 .info = snd_soc_info_volsw, \
150 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
151 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
Philipp Zabela7a4ac82008-01-10 14:37:42 +0100152 ((max) << 16) | ((invert) << 24) }
153#define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
154{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
155 .info = snd_soc_info_volsw, \
156 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
157 .tlv.p = (tlv_array), \
158 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
159 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
160#define SOC_DAPM_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, \
161 power, tlv_array) \
162{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
163 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
164 .tlv.p = (tlv_array), \
165 .info = snd_soc_info_volsw, \
166 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
167 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
168 ((max) << 16) | ((invert) << 24) }
Richard Purdie808db4a2006-10-06 18:20:14 +0200169#define SOC_DAPM_ENUM(xname, xenum) \
170{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
171 .info = snd_soc_info_enum_double, \
172 .get = snd_soc_dapm_get_enum_double, \
173 .put = snd_soc_dapm_put_enum_double, \
174 .private_value = (unsigned long)&xenum }
175
176/* dapm stream operations */
177#define SND_SOC_DAPM_STREAM_NOP 0x0
178#define SND_SOC_DAPM_STREAM_START 0x1
179#define SND_SOC_DAPM_STREAM_STOP 0x2
180#define SND_SOC_DAPM_STREAM_SUSPEND 0x4
181#define SND_SOC_DAPM_STREAM_RESUME 0x8
182#define SND_SOC_DAPM_STREAM_PAUSE_PUSH 0x10
183#define SND_SOC_DAPM_STREAM_PAUSE_RELEASE 0x20
184
185/* dapm event types */
186#define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
187#define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
188#define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
189#define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
190#define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
191#define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
192
193/* convenience event type detection */
194#define SND_SOC_DAPM_EVENT_ON(e) \
195 (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
196#define SND_SOC_DAPM_EVENT_OFF(e) \
197 (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
198
199struct snd_soc_dapm_widget;
200enum snd_soc_dapm_type;
201struct snd_soc_dapm_path;
202struct snd_soc_dapm_pin;
Mark Brown105f1c22008-05-13 14:52:19 +0200203struct snd_soc_dapm_route;
Richard Purdie808db4a2006-10-06 18:20:14 +0200204
Mark Brown11589412008-07-29 11:42:23 +0100205int dapm_reg_event(struct snd_soc_dapm_widget *w,
206 struct snd_kcontrol *kcontrol, int event);
207
Richard Purdie808db4a2006-10-06 18:20:14 +0200208/* dapm controls */
209int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_value *ucontrol);
211int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_value *ucontrol);
213int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
214 struct snd_ctl_elem_value *ucontrol);
215int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
216 struct snd_ctl_elem_value *ucontrol);
217int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
218 const struct snd_soc_dapm_widget *widget);
Mark Brown4ba13272008-05-13 14:51:19 +0200219int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
220 const struct snd_soc_dapm_widget *widget,
221 int num);
Richard Purdie808db4a2006-10-06 18:20:14 +0200222
223/* dapm path setup */
Mark Brown105f1c22008-05-13 14:52:19 +0200224int __deprecated snd_soc_dapm_connect_input(struct snd_soc_codec *codec,
Richard Purdie808db4a2006-10-06 18:20:14 +0200225 const char *sink_name, const char *control_name, const char *src_name);
226int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec);
227void snd_soc_dapm_free(struct snd_soc_device *socdev);
Mark Brown105f1c22008-05-13 14:52:19 +0200228int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
229 const struct snd_soc_dapm_route *route, int num);
Richard Purdie808db4a2006-10-06 18:20:14 +0200230
231/* dapm events */
232int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
233 int event);
Mark Brown0be98982008-05-19 12:31:28 +0200234int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
235 enum snd_soc_bias_level level);
Richard Purdie808db4a2006-10-06 18:20:14 +0200236
237/* dapm sys fs - used by the core */
238int snd_soc_dapm_sys_add(struct device *dev);
239
Liam Girdwooda5302182008-07-07 13:35:17 +0100240/* dapm audio pin control and status */
241int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin);
242int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin);
243int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin);
244int snd_soc_dapm_sync(struct snd_soc_codec *codec);
Richard Purdie808db4a2006-10-06 18:20:14 +0200245
246/* dapm widget types */
247enum snd_soc_dapm_type {
248 snd_soc_dapm_input = 0, /* input pin */
249 snd_soc_dapm_output, /* output pin */
250 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
251 snd_soc_dapm_mixer, /* mixes several analog signals together */
252 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
253 snd_soc_dapm_adc, /* analog to digital converter */
254 snd_soc_dapm_dac, /* digital to analog converter */
255 snd_soc_dapm_micbias, /* microphone bias (power) */
256 snd_soc_dapm_mic, /* microphone */
257 snd_soc_dapm_hp, /* headphones */
258 snd_soc_dapm_spk, /* speaker */
259 snd_soc_dapm_line, /* line input/output */
260 snd_soc_dapm_switch, /* analog switch */
261 snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */
262 snd_soc_dapm_pre, /* machine specific pre widget - exec first */
263 snd_soc_dapm_post, /* machine specific post widget - exec last */
264};
265
Mark Brown105f1c22008-05-13 14:52:19 +0200266/*
267 * DAPM audio route definition.
268 *
269 * Defines an audio route originating at source via control and finishing
270 * at sink.
271 */
272struct snd_soc_dapm_route {
273 const char *sink;
274 const char *control;
275 const char *source;
276};
277
Richard Purdie808db4a2006-10-06 18:20:14 +0200278/* dapm audio path between two widgets */
279struct snd_soc_dapm_path {
280 char *name;
281 char *long_name;
282
283 /* source (input) and sink (output) widgets */
284 struct snd_soc_dapm_widget *source;
285 struct snd_soc_dapm_widget *sink;
286 struct snd_kcontrol *kcontrol;
287
288 /* status */
289 u32 connect:1; /* source and sink widgets are connected */
290 u32 walked:1; /* path has been walked */
291
292 struct list_head list_source;
293 struct list_head list_sink;
294 struct list_head list;
295};
296
297/* dapm widget */
298struct snd_soc_dapm_widget {
299 enum snd_soc_dapm_type id;
300 char *name; /* widget name */
301 char *sname; /* stream name */
302 struct snd_soc_codec *codec;
303 struct list_head list;
304
305 /* dapm control */
306 short reg; /* negative reg = no direct dapm */
307 unsigned char shift; /* bits to shift */
308 unsigned int saved_value; /* widget saved value */
309 unsigned int value; /* widget current value */
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300310 unsigned int mask; /* non-shifted mask */
311 unsigned int on_val; /* on state value */
312 unsigned int off_val; /* off state value */
Richard Purdie808db4a2006-10-06 18:20:14 +0200313 unsigned char power:1; /* block power status */
314 unsigned char invert:1; /* invert the power bit */
315 unsigned char active:1; /* active stream on DAC, ADC's */
316 unsigned char connected:1; /* connected codec pin */
317 unsigned char new:1; /* cnew complete */
318 unsigned char ext:1; /* has external widgets */
319 unsigned char muted:1; /* muted for pop reduction */
320 unsigned char suspend:1; /* was active before suspend */
321 unsigned char pmdown:1; /* waiting for timeout */
322
323 /* external events */
324 unsigned short event_flags; /* flags to specify event types */
Laim Girdwood9af6d952008-01-10 14:41:02 +0100325 int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
Richard Purdie808db4a2006-10-06 18:20:14 +0200326
327 /* kcontrols that relate to this widget */
328 int num_kcontrols;
329 const struct snd_kcontrol_new *kcontrols;
330
331 /* widget input and outputs */
332 struct list_head sources;
333 struct list_head sinks;
334};
335
336#endif