001 Dynamic Audio Power Management for Portable Devices
002 ===================================================
003
004 1. Description
005 ==============
006
007 Dynamic Audio Power Management (DAPM) is designed to allow portable
008 Linux devices to use the minimum amount of power within the audio
009 subsystem at all times. It is independent of other kernel PM and as
010 such, can easily co-exist with the other PM systems.
011
012 DAPM is also completely transparent to all user space applications as
013 all power switching is done within the ASoC core. No code changes or
014 recompiling are required for user space applications. DAPM makes power
015 switching decisions based upon any audio stream (capture/playback)
016 activity and audio mixer settings within the device.
017
018 DAPM spans the whole machine. It covers power control within the entire
019 audio subsystem, this includes internal codec power blocks and machine
020 level power systems.
021
022 There are 4 power domains within DAPM
023
024 1. Codec domain - VREF, VMID (core codec and audio power)
025 Usually controlled at codec probe/remove and suspend/resume, although
026 can be set at stream time if power is not needed for sidetone, etc.
027
028 2. Platform/Machine domain - physically connected inputs and outputs
029 Is platform/machine and user action specific, is configured by the
030 machine driver and responds to asynchronous events e.g when HP
031 are inserted
032
033 3. Path domain - audio susbsystem signal paths
034 Automatically set when mixer and mux settings are changed by the user.
035 e.g. alsamixer, amixer.
036
037 4. Stream domain - DACs and ADCs.
038 Enabled and disabled when stream playback/capture is started and
039 stopped respectively. e.g. aplay, arecord.
040
041 All DAPM power switching decisions are made automatically by consulting an audio
042 routing map of the whole machine. This map is specific to each machine and
043 consists of the interconnections between every audio component (including
044 internal codec components). All audio components that effect power are called
045 widgets hereafter.
046
047
048 2. DAPM Widgets
049 ===============
050
051 Audio DAPM widgets fall into a number of types:-
052
053 o Mixer - Mixes several analog signals into a single analog signal.
054 o Mux - An analog switch that outputs only one of many inputs.
055 o PGA - A programmable gain amplifier or attenuation widget.
056 o ADC - Analog to Digital Converter
057 o DAC - Digital to Analog Converter
058 o Switch - An analog switch
059 o Input - A codec input pin
060 o Output - A codec output pin
061 o Headphone - Headphone (and optional Jack)
062 o Mic - Mic (and optional Jack)
063 o Line - Line Input/Output (and optional Jack)
064 o Speaker - Speaker
065 o Supply - Power or clock supply widget used by other widgets.
066 o Pre - Special PRE widget (exec before all others)
067 o Post - Special POST widget (exec after all others)
068
069 (Widgets are defined in include/sound/soc-dapm.h)
070
071 Widgets are usually added in the codec driver and the machine driver. There are
072 convenience macros defined in soc-dapm.h that can be used to quickly build a
073 list of widgets of the codecs and machines DAPM widgets.
074
075 Most widgets have a name, register, shift and invert. Some widgets have extra
076 parameters for stream name and kcontrols.
077
078
079 2.1 Stream Domain Widgets
080 -------------------------
081
082 Stream Widgets relate to the stream power domain and only consist of ADCs
083 (analog to digital converters) and DACs (digital to analog converters).
084
085 Stream widgets have the following format:-
086
087 SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),
088
089 NOTE: the stream name must match the corresponding stream name in your codec
090 snd_soc_codec_dai.
091
092 e.g. stream widgets for HiFi playback and capture
093
094 SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1),
095 SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),
096
097
098 2.2 Path Domain Widgets
099 -----------------------
100
101 Path domain widgets have a ability to control or affect the audio signal or
102 audio paths within the audio subsystem. They have the following form:-
103
104 SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)
105
106 Any widget kcontrols can be set using the controls and num_controls members.
107
108 e.g. Mixer widget (the kcontrols are declared first)
109
110 /* Output Mixer */
111 static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
112 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
113 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
114 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
115 };
116
117 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
118 ARRAY_SIZE(wm8731_output_mixer_controls)),
119
120 If you dont want the mixer elements prefixed with the name of the mixer widget,
121 you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same
122 as for SND_SOC_DAPM_MIXER.
123
124 2.3 Platform/Machine domain Widgets
125 -----------------------------------
126
127 Machine widgets are different from codec widgets in that they don't have a
128 codec register bit associated with them. A machine widget is assigned to each
129 machine audio component (non codec) that can be independently powered. e.g.
130
131 o Speaker Amp
132 o Microphone Bias
133 o Jack connectors
134
135 A machine widget can have an optional call back.
136
137 e.g. Jack connector widget for an external Mic that enables Mic Bias
138 when the Mic is inserted:-
139
140 static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event)
141 {
142 gpio_set_value(SPITZ_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event));
143 return 0;
144 }
145
146 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
147
148
149 2.4 Codec Domain
150 ----------------
151
152 The codec power domain has no widgets and is handled by the codecs DAPM event
153 handler. This handler is called when the codec powerstate is changed wrt to any
154 stream event or by kernel PM events.
155
156
157 2.5 Virtual Widgets
158 -------------------
159
160 Sometimes widgets exist in the codec or machine audio map that don't have any
161 corresponding soft power control. In this case it is necessary to create
162 a virtual widget - a widget with no control bits e.g.
163
164 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
165
166 This can be used to merge to signal paths together in software.
167
168 After all the widgets have been defined, they can then be added to the DAPM
169 subsystem individually with a call to snd_soc_dapm_new_control().
170
171
172 3. Codec Widget Interconnections
173 ================================
174
175 Widgets are connected to each other within the codec and machine by audio paths
176 (called interconnections). Each interconnection must be defined in order to
177 create a map of all audio paths between widgets.
178
179 This is easiest with a diagram of the codec (and schematic of the machine audio
180 system), as it requires joining widgets together via their audio signal paths.
181
182 e.g., from the WM8731 output mixer (wm8731.c)
183
184 The WM8731 output mixer has 3 inputs (sources)
185
186 1. Line Bypass Input
187 2. DAC (HiFi playback)
188 3. Mic Sidetone Input
189
190 Each input in this example has a kcontrol associated with it (defined in example
191 above) and is connected to the output mixer via it's kcontrol name. We can now
192 connect the destination widget (wrt audio signal) with it's source widgets.
193
194 /* output mixer */
195 {"Output Mixer", "Line Bypass Switch", "Line Input"},
196 {"Output Mixer", "HiFi Playback Switch", "DAC"},
197 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
198
199 So we have :-
200
201 Destination Widget <=== Path Name <=== Source Widget
202
203 Or:-
204
205 Sink, Path, Source
206
207 Or :-
208
209 "Output Mixer" is connected to the "DAC" via the "HiFi Playback Switch".
210
211 When there is no path name connecting widgets (e.g. a direct connection) we
212 pass NULL for the path name.
213
214 Interconnections are created with a call to:-
215
216 snd_soc_dapm_connect_input(codec, sink, path, source);
217
218 Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and
219 interconnections have been registered with the core. This causes the core to
220 scan the codec and machine so that the internal DAPM state matches the
221 physical state of the machine.
222
223
224 3.1 Machine Widget Interconnections
225 -----------------------------------
226 Machine widget interconnections are created in the same way as codec ones and
227 directly connect the codec pins to machine level widgets.
228
229 e.g. connects the speaker out codec pins to the internal speaker.
230
231 /* ext speaker connected to codec pins LOUT2, ROUT2 */
232 {"Ext Spk", NULL , "ROUT2"},
233 {"Ext Spk", NULL , "LOUT2"},
234
235 This allows the DAPM to power on and off pins that are connected (and in use)
236 and pins that are NC respectively.
237
238
239 4 Endpoint Widgets
240 ===================
241 An endpoint is a start or end point (widget) of an audio signal within the
242 machine and includes the codec. e.g.
243
244 o Headphone Jack
245 o Internal Speaker
246 o Internal Mic
247 o Mic Jack
248 o Codec Pins
249
250 When a codec pin is NC it can be marked as not used with a call to
251
252 snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);
253
254 The last argument is 0 for inactive and 1 for active. This way the pin and its
255 input widget will never be powered up and consume power.
256
257 This also applies to machine widgets. e.g. if a headphone is connected to a
258 jack then the jack can be marked active. If the headphone is removed, then
259 the headphone jack can be marked inactive.
260
261
262 5 DAPM Widget Events
263 ====================
264
265 Some widgets can register their interest with the DAPM core in PM events.
266 e.g. A Speaker with an amplifier registers a widget so the amplifier can be
267 powered only when the spk is in use.
268
269 /* turn speaker amplifier on/off depending on use */
270 static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
271 {
272 gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event));
273 return 0;
274 }
275
276 /* corgi machine dapm widgets */
277 static const struct snd_soc_dapm_widget wm8731_dapm_widgets =
278 SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);
279
280 Please see soc-dapm.h for all other widgets that support events.
281
282
283 5.1 Event types
284 ---------------
285
286 The following event types are supported by event widgets.
287
288 /* dapm event types */
289 #define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
290 #define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
291 #define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
292 #define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
293 #define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
294 #define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
阅读(1563) | 评论(0) | 转发(0) |