1 Dynamic Audio Power Management for Portable Devices
2 ===================================================
7 Dynamic Audio Power Management (DAPM) is designed to allow portable
8 Linux devices to use the minimum amount of power within the audio
9 subsystem at all times. It is independent of other kernel PM and as
10 such, can easily co-exist with the other PM systems.
12 DAPM is also completely transparent to all user space applications as
13 all power switching is done within the ASoC core. No code changes or
14 recompiling are required for user space applications. DAPM makes power
15 switching decisions based upon any audio stream (capture/playback)
16 activity and audio mixer settings within the device.
18 DAPM spans the whole machine. It covers power control within the entire
19 audio subsystem, this includes internal codec power blocks and machine
22 There are 4 power domains within DAPM
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.
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
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.
37 4. Stream domain - DACs and ADCs.
38 Enabled and disabled when stream playback/capture is started and
39 stopped respectively. e.g. aplay, arecord.
41 All DAPM power switching decisions are made automatically by consulting an audio
42 routing map of the whole machine. This map is specific to each machine and
43 consists of the interconnections between every audio component (including
44 internal codec components). All audio components that effect power are called
51 Audio DAPM widgets fall into a number of types:-
53 o Mixer - Mixes several analog signals into a single analog signal.
54 o Mux - An analog switch that outputs only one of many inputs.
55 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)
65 o Pre - Special PRE widget (exec before all others)
66 o Post - Special POST widget (exec after all others)
68 (Widgets are defined in include/sound/soc-dapm.h)
70 Widgets are usually added in the codec driver and the machine driver. There are
71 convenience macros defined in soc-dapm.h that can be used to quickly build a
72 list of widgets of the codecs and machines DAPM widgets.
74 Most widgets have a name, register, shift and invert. Some widgets have extra
75 parameters for stream name and kcontrols.
78 2.1 Stream Domain Widgets
79 -------------------------
81 Stream Widgets relate to the stream power domain and only consist of ADCs
82 (analog to digital converters) and DACs (digital to analog converters).
84 Stream widgets have the following format:-
86 SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),
88 NOTE: the stream name must match the corresponding stream name in your codec
91 e.g. stream widgets for HiFi playback and capture
93 SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1),
94 SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),
97 2.2 Path Domain Widgets
98 -----------------------
100 Path domain widgets have a ability to control or affect the audio signal or
101 audio paths within the audio subsystem. They have the following form:-
103 SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)
105 Any widget kcontrols can be set using the controls and num_controls members.
107 e.g. Mixer widget (the kcontrols are declared first)
110 static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
111 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
112 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
113 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
116 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
117 ARRAY_SIZE(wm8731_output_mixer_controls)),
119 If you dont want the mixer elements prefixed with the name of the mixer widget,
120 you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same
121 as for SND_SOC_DAPM_MIXER.
123 2.3 Platform/Machine domain Widgets
124 -----------------------------------
126 Machine widgets are different from codec widgets in that they don't have a
127 codec register bit associated with them. A machine widget is assigned to each
128 machine audio component (non codec) that can be independently powered. e.g.
134 A machine widget can have an optional call back.
136 e.g. Jack connector widget for an external Mic that enables Mic Bias
137 when the Mic is inserted:-
139 static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event)
141 gpio_set_value(SPITZ_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event));
145 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
151 The codec power domain has no widgets and is handled by the codecs DAPM event
152 handler. This handler is called when the codec powerstate is changed wrt to any
153 stream event or by kernel PM events.
159 Sometimes widgets exist in the codec or machine audio map that don't have any
160 corresponding soft power control. In this case it is necessary to create
161 a virtual widget - a widget with no control bits e.g.
163 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
165 This can be used to merge to signal paths together in software.
167 After all the widgets have been defined, they can then be added to the DAPM
168 subsystem individually with a call to snd_soc_dapm_new_control().
171 3. Codec Widget Interconnections
172 ================================
174 Widgets are connected to each other within the codec and machine by audio paths
175 (called interconnections). Each interconnection must be defined in order to
176 create a map of all audio paths between widgets.
178 This is easiest with a diagram of the codec (and schematic of the machine audio
179 system), as it requires joining widgets together via their audio signal paths.
181 e.g., from the WM8731 output mixer (wm8731.c)
183 The WM8731 output mixer has 3 inputs (sources)
186 2. DAC (HiFi playback)
187 3. Mic Sidetone Input
189 Each input in this example has a kcontrol associated with it (defined in example
190 above) and is connected to the output mixer via it's kcontrol name. We can now
191 connect the destination widget (wrt audio signal) with it's source widgets.
194 {"Output Mixer", "Line Bypass Switch", "Line Input"},
195 {"Output Mixer", "HiFi Playback Switch", "DAC"},
196 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
200 Destination Widget <=== Path Name <=== Source Widget
208 "Output Mixer" is connected to the "DAC" via the "HiFi Playback Switch".
210 When there is no path name connecting widgets (e.g. a direct connection) we
211 pass NULL for the path name.
213 Interconnections are created with a call to:-
215 snd_soc_dapm_connect_input(codec, sink, path, source);
217 Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and
218 interconnections have been registered with the core. This causes the core to
219 scan the codec and machine so that the internal DAPM state matches the
220 physical state of the machine.
223 3.1 Machine Widget Interconnections
224 -----------------------------------
225 Machine widget interconnections are created in the same way as codec ones and
226 directly connect the codec pins to machine level widgets.
228 e.g. connects the speaker out codec pins to the internal speaker.
230 /* ext speaker connected to codec pins LOUT2, ROUT2 */
231 {"Ext Spk", NULL , "ROUT2"},
232 {"Ext Spk", NULL , "LOUT2"},
234 This allows the DAPM to power on and off pins that are connected (and in use)
235 and pins that are NC respectively.
240 An endpoint is a start or end point (widget) of an audio signal within the
241 machine and includes the codec. e.g.
249 When a codec pin is NC it can be marked as not used with a call to
251 snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);
253 The last argument is 0 for inactive and 1 for active. This way the pin and its
254 input widget will never be powered up and consume power.
256 This also applies to machine widgets. e.g. if a headphone is connected to a
257 jack then the jack can be marked active. If the headphone is removed, then
258 the headphone jack can be marked inactive.
264 Some widgets can register their interest with the DAPM core in PM events.
265 e.g. A Speaker with an amplifier registers a widget so the amplifier can be
266 powered only when the spk is in use.
268 /* turn speaker amplifier on/off depending on use */
269 static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
271 gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event));
275 /* corgi machine dapm widgets */
276 static const struct snd_soc_dapm_widget wm8731_dapm_widgets =
277 SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);
279 Please see soc-dapm.h for all other widgets that support events.
285 The following event types are supported by event widgets.
287 /* dapm event types */
288 #define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
289 #define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
290 #define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
291 #define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
292 #define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
293 #define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */