blob: 46f9684d0b29d8550824073f0ddf925035b5c327 [file] [log] [blame]
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +02001Dynamic Audio Power Management for Portable Devices
2===================================================
3
41. Description
5==============
6
Mark Brown7c4dbbd2008-01-23 08:41:46 +01007Dynamic Audio Power Management (DAPM) is designed to allow portable
8Linux devices to use the minimum amount of power within the audio
9subsystem at all times. It is independent of other kernel PM and as
10such, can easily co-exist with the other PM systems.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020011
Mark Brown7c4dbbd2008-01-23 08:41:46 +010012DAPM is also completely transparent to all user space applications as
13all power switching is done within the ASoC core. No code changes or
14recompiling are required for user space applications. DAPM makes power
15switching decisions based upon any audio stream (capture/playback)
16activity and audio mixer settings within the device.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020017
Mark Brown7c4dbbd2008-01-23 08:41:46 +010018DAPM spans the whole machine. It covers power control within the entire
19audio subsystem, this includes internal codec power blocks and machine
20level power systems.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020021
22There are 4 power domains within DAPM
23
24 1. Codec domain - VREF, VMID (core codec and audio power)
25 Usually controlled at codec probe/remove and suspend/resume, although
26 can be set at stream time if power is not needed for sidetone, etc.
27
28 2. Platform/Machine domain - physically connected inputs and outputs
29 Is platform/machine and user action specific, is configured by the
30 machine driver and responds to asynchronous events e.g when HP
31 are inserted
32
33 3. Path domain - audio susbsystem signal paths
34 Automatically set when mixer and mux settings are changed by the user.
35 e.g. alsamixer, amixer.
36
Mark Brown7c4dbbd2008-01-23 08:41:46 +010037 4. Stream domain - DACs and ADCs.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020038 Enabled and disabled when stream playback/capture is started and
39 stopped respectively. e.g. aplay, arecord.
40
Matt LaPlante01dd2fb2007-10-20 01:34:40 +020041All DAPM power switching decisions are made automatically by consulting an audio
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020042routing map of the whole machine. This map is specific to each machine and
43consists of the interconnections between every audio component (including
44internal codec components). All audio components that effect power are called
45widgets hereafter.
46
47
482. DAPM Widgets
49===============
50
51Audio DAPM widgets fall into a number of types:-
52
53 o Mixer - Mixes several analog signals into a single analog signal.
Mark Brown7c4dbbd2008-01-23 08:41:46 +010054 o Mux - An analog switch that outputs only one of many inputs.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020055 o PGA - A programmable gain amplifier or attenuation widget.
56 o ADC - Analog to Digital Converter
57 o DAC - Digital to Analog Converter
58 o Switch - An analog switch
59 o Input - A codec input pin
60 o Output - A codec output pin
61 o Headphone - Headphone (and optional Jack)
62 o Mic - Mic (and optional Jack)
63 o Line - Line Input/Output (and optional Jack)
64 o Speaker - Speaker
65 o Pre - Special PRE widget (exec before all others)
66 o Post - Special POST widget (exec after all others)
67
68(Widgets are defined in include/sound/soc-dapm.h)
69
70Widgets are usually added in the codec driver and the machine driver. There are
Matt LaPlanted9195882008-07-25 19:45:33 -070071convenience macros defined in soc-dapm.h that can be used to quickly build a
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020072list of widgets of the codecs and machines DAPM widgets.
73
74Most widgets have a name, register, shift and invert. Some widgets have extra
75parameters for stream name and kcontrols.
76
77
782.1 Stream Domain Widgets
79-------------------------
80
Mark Brown7c4dbbd2008-01-23 08:41:46 +010081Stream Widgets relate to the stream power domain and only consist of ADCs
82(analog to digital converters) and DACs (digital to analog converters).
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020083
84Stream widgets have the following format:-
85
86SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),
87
Mark Brown7c4dbbd2008-01-23 08:41:46 +010088NOTE: the stream name must match the corresponding stream name in your codec
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +020089snd_soc_codec_dai.
90
91e.g. stream widgets for HiFi playback and capture
92
93SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1),
94SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),
95
96
972.2 Path Domain Widgets
98-----------------------
99
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100100Path domain widgets have a ability to control or affect the audio signal or
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200101audio paths within the audio subsystem. They have the following form:-
102
103SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)
104
105Any widget kcontrols can be set using the controls and num_controls members.
106
107e.g. Mixer widget (the kcontrols are declared first)
108
109/* Output Mixer */
110static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
111SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
112SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
113SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
114};
115
116SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
117 ARRAY_SIZE(wm8731_output_mixer_controls)),
118
119
1202.3 Platform/Machine domain Widgets
121-----------------------------------
122
123Machine widgets are different from codec widgets in that they don't have a
124codec register bit associated with them. A machine widget is assigned to each
125machine audio component (non codec) that can be independently powered. e.g.
126
127 o Speaker Amp
128 o Microphone Bias
129 o Jack connectors
130
131A machine widget can have an optional call back.
132
133e.g. Jack connector widget for an external Mic that enables Mic Bias
134when the Mic is inserted:-
135
136static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event)
137{
Eric Miaofec12a62008-09-19 02:15:08 +0800138 gpio_set_value(SPITZ_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event));
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200139 return 0;
140}
141
142SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
143
144
1452.4 Codec Domain
146----------------
147
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100148The codec power domain has no widgets and is handled by the codecs DAPM event
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200149handler. This handler is called when the codec powerstate is changed wrt to any
150stream event or by kernel PM events.
151
152
1532.5 Virtual Widgets
154-------------------
155
156Sometimes widgets exist in the codec or machine audio map that don't have any
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100157corresponding soft power control. In this case it is necessary to create
158a virtual widget - a widget with no control bits e.g.
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200159
160SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
161
162This can be used to merge to signal paths together in software.
163
164After all the widgets have been defined, they can then be added to the DAPM
165subsystem individually with a call to snd_soc_dapm_new_control().
166
167
1683. Codec Widget Interconnections
169================================
170
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100171Widgets are connected to each other within the codec and machine by audio paths
172(called interconnections). Each interconnection must be defined in order to
173create a map of all audio paths between widgets.
174
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200175This is easiest with a diagram of the codec (and schematic of the machine audio
176system), as it requires joining widgets together via their audio signal paths.
177
Mark Brown7c4dbbd2008-01-23 08:41:46 +0100178e.g., from the WM8731 output mixer (wm8731.c)
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200179
180The WM8731 output mixer has 3 inputs (sources)
181
182 1. Line Bypass Input
183 2. DAC (HiFi playback)
184 3. Mic Sidetone Input
185
186Each input in this example has a kcontrol associated with it (defined in example
187above) and is connected to the output mixer via it's kcontrol name. We can now
188connect the destination widget (wrt audio signal) with it's source widgets.
189
190 /* output mixer */
191 {"Output Mixer", "Line Bypass Switch", "Line Input"},
192 {"Output Mixer", "HiFi Playback Switch", "DAC"},
193 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
194
195So we have :-
196
197 Destination Widget <=== Path Name <=== Source Widget
198
199Or:-
200
201 Sink, Path, Source
202
203Or :-
204
205 "Output Mixer" is connected to the "DAC" via the "HiFi Playback Switch".
206
207When there is no path name connecting widgets (e.g. a direct connection) we
208pass NULL for the path name.
209
210Interconnections are created with a call to:-
211
212snd_soc_dapm_connect_input(codec, sink, path, source);
213
214Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and
215interconnections have been registered with the core. This causes the core to
216scan the codec and machine so that the internal DAPM state matches the
217physical state of the machine.
218
219
2203.1 Machine Widget Interconnections
221-----------------------------------
222Machine widget interconnections are created in the same way as codec ones and
223directly connect the codec pins to machine level widgets.
224
225e.g. connects the speaker out codec pins to the internal speaker.
226
227 /* ext speaker connected to codec pins LOUT2, ROUT2 */
228 {"Ext Spk", NULL , "ROUT2"},
229 {"Ext Spk", NULL , "LOUT2"},
230
231This allows the DAPM to power on and off pins that are connected (and in use)
232and pins that are NC respectively.
233
234
2354 Endpoint Widgets
236===================
237An endpoint is a start or end point (widget) of an audio signal within the
238machine and includes the codec. e.g.
239
240 o Headphone Jack
241 o Internal Speaker
242 o Internal Mic
243 o Mic Jack
244 o Codec Pins
245
246When a codec pin is NC it can be marked as not used with a call to
247
248snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);
249
250The last argument is 0 for inactive and 1 for active. This way the pin and its
251input widget will never be powered up and consume power.
252
253This also applies to machine widgets. e.g. if a headphone is connected to a
254jack then the jack can be marked active. If the headphone is removed, then
255the headphone jack can be marked inactive.
256
257
2585 DAPM Widget Events
259====================
260
261Some widgets can register their interest with the DAPM core in PM events.
262e.g. A Speaker with an amplifier registers a widget so the amplifier can be
263powered only when the spk is in use.
264
265/* turn speaker amplifier on/off depending on use */
266static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
267{
Eric Miaofec12a62008-09-19 02:15:08 +0800268 gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event));
Liam Girdwoodeb1a6af2006-10-06 18:34:51 +0200269 return 0;
270}
271
272/* corgi machine dapm widgets */
273static const struct snd_soc_dapm_widget wm8731_dapm_widgets =
274 SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);
275
276Please see soc-dapm.h for all other widgets that support events.
277
278
2795.1 Event types
280---------------
281
282The following event types are supported by event widgets.
283
284/* dapm event types */
285#define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
286#define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
287#define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
288#define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
289#define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
290#define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */