1 ============================================== 2 Dynamic Audio Power Management for Portable De 3 ============================================== 4 5 Description 6 =========== 7 8 Dynamic Audio Power Management (DAPM) is desig 9 Linux devices to use the minimum amount of pow 10 subsystem at all times. It is independent of o 11 management frameworks and, as such, can easily 12 13 DAPM is also completely transparent to all use 14 all power switching is done within the ASoC co 15 recompiling are required for user space applic 16 switching decisions based upon any audio strea 17 activity and audio mixer settings within the d 18 19 DAPM is based on two basic elements, called wi 20 21 * a **widget** is every part of the audio har 22 software when in use and disabled to save p 23 * a **route** is an interconnection between w 24 can flow from one widget to the other 25 26 All DAPM power switching decisions are made au 27 audio routing graph. This graph is specific to 28 the whole sound card, so some DAPM routes conn 29 different components (e.g. the LINE OUT pin of 30 an amplifier). 31 32 The graph for the STM32MP1-DK1 sound card is s 33 34 .. kernel-figure:: dapm-graph.svg 35 :alt: Example DAPM graph 36 :align: center 37 38 DAPM power domains 39 ================== 40 41 There are 4 power domains within DAPM: 42 43 Codec bias domain 44 VREF, VMID (core codec and audio power) 45 46 Usually controlled at codec probe/remove 47 can be set at stream time if power is no 48 49 Platform/Machine domain 50 physically connected inputs and outputs 51 52 Is platform/machine and user action spec 53 machine driver and responds to asynchron 54 are inserted 55 56 Path domain 57 audio subsystem signal paths 58 59 Automatically set when mixer and mux set 60 e.g. alsamixer, amixer. 61 62 Stream domain 63 DACs and ADCs. 64 65 Enabled and disabled when stream playbac 66 stopped respectively. e.g. aplay, arecor 67 68 69 DAPM Widgets 70 ============ 71 72 Audio DAPM widgets fall into a number of types 73 74 Mixer 75 Mixes several analog signals into a si 76 Mux 77 An analog switch that outputs only one 78 PGA 79 A programmable gain amplifier or atten 80 ADC 81 Analog to Digital Converter 82 DAC 83 Digital to Analog Converter 84 Switch 85 An analog switch 86 Input 87 A codec input pin 88 Output 89 A codec output pin 90 Headphone 91 Headphone (and optional Jack) 92 Mic 93 Mic (and optional Jack) 94 Line 95 Line Input/Output (and optional Jack) 96 Speaker 97 Speaker 98 Supply 99 Power or clock supply widget used by o 100 Regulator 101 External regulator that supplies power 102 Clock 103 External clock that supplies clock to 104 AIF IN 105 Audio Interface Input (with TDM slot m 106 AIF OUT 107 Audio Interface Output (with TDM slot 108 Siggen 109 Signal Generator. 110 DAI IN 111 Digital Audio Interface Input. 112 DAI OUT 113 Digital Audio Interface Output. 114 DAI Link 115 DAI Link between two DAI structures 116 Pre 117 Special PRE widget (exec before all ot 118 Post 119 Special POST widget (exec after all ot 120 Buffer 121 Inter widget audio data buffer within 122 Scheduler 123 DSP internal scheduler that schedules 124 work. 125 Effect 126 Widget that performs an audio processi 127 SRC 128 Sample Rate Converter within DSP or CO 129 ASRC 130 Asynchronous Sample Rate Converter wit 131 Encoder 132 Widget that encodes audio data from on 133 usually more compressed format. 134 Decoder 135 Widget that decodes audio data from a 136 uncompressed format like PCM. 137 138 139 (Widgets are defined in include/sound/soc-dapm 140 141 Widgets can be added to the sound card by any 142 There are convenience macros defined in soc-da 143 build a list of widgets of the codecs and mach 144 145 Most widgets have a name, register, shift and 146 parameters for stream name and kcontrols. 147 148 149 Stream Domain Widgets 150 --------------------- 151 152 Stream Widgets relate to the stream power doma 153 (analog to digital converters), DACs (digital 154 AIF IN and AIF OUT. 155 156 Stream widgets have the following format: 157 :: 158 159 SND_SOC_DAPM_DAC(name, stream name, reg, shi 160 SND_SOC_DAPM_AIF_IN(name, stream, slot, reg, 161 162 NOTE: the stream name must match the correspon 163 snd_soc_dai_driver. 164 165 e.g. stream widgets for HiFi playback and capt 166 :: 167 168 SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback" 169 SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", 170 171 e.g. stream widgets for AIF 172 :: 173 174 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback 175 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture 176 177 178 Path Domain Widgets 179 ------------------- 180 181 Path domain widgets have a ability to control 182 audio paths within the audio subsystem. They h 183 :: 184 185 SND_SOC_DAPM_PGA(name, reg, shift, invert, c 186 187 Any widget kcontrols can be set using the cont 188 189 e.g. Mixer widget (the kcontrols are declared 190 :: 191 192 /* Output Mixer */ 193 static const snd_kcontrol_new_t wm8731_outpu 194 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731 195 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM873 196 SOC_DAPM_SINGLE("HiFi Playback Switch", WM87 197 }; 198 199 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PW 200 ARRAY_SIZE(wm8731_output_mixer_control 201 202 If you don't want the mixer elements prefixed 203 you can use SND_SOC_DAPM_MIXER_NAMED_CTL inste 204 as for SND_SOC_DAPM_MIXER. 205 206 207 Machine domain Widgets 208 ---------------------- 209 210 Machine widgets are different from codec widge 211 codec register bit associated with them. A mac 212 machine audio component (non codec or DSP) tha 213 powered. e.g. 214 215 * Speaker Amp 216 * Microphone Bias 217 * Jack connectors 218 219 A machine widget can have an optional call bac 220 221 e.g. Jack connector widget for an external Mic 222 when the Mic is inserted:: 223 224 static int spitz_mic_bias(struct snd_soc_dap 225 { 226 gpio_set_value(SPITZ_GPIO_MIC_BIAS, SN 227 return 0; 228 } 229 230 SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias) 231 232 233 Codec (BIAS) Domain 234 ------------------- 235 236 The codec bias power domain has no widgets and 237 event handler. This handler is called when the 238 to any stream event or by kernel PM events. 239 240 241 Virtual Widgets 242 --------------- 243 244 Sometimes widgets exist in the codec or machin 245 corresponding soft power control. In this case 246 a virtual widget - a widget with no control bi 247 :: 248 249 SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOP 250 251 This can be used to merge two signal paths tog 252 253 Registering DAPM controls 254 ========================= 255 256 In many cases the DAPM widgets are implemented 257 const struct snd_soc_dapm_widget`` array in a 258 declared via the ``dapm_widgets`` and ``num_da 259 ``struct snd_soc_component_driver``. 260 261 Similarly, routes connecting them are implemen 262 const struct snd_soc_dapm_route`` array and de 263 ``dapm_routes`` and ``num_dapm_routes`` fields 264 265 With the above declared, the driver registrati 266 populating them:: 267 268 static const struct snd_soc_dapm_widget wm20 269 SND_SOC_DAPM_OUTPUT("SPKN"), 270 SND_SOC_DAPM_OUTPUT("SPKP"), 271 ... 272 }; 273 274 /* Target, Path, Source */ 275 static const struct snd_soc_dapm_route wm200 276 { "SPKN", NULL, "ANC Engine" }, 277 { "SPKP", NULL, "ANC Engine" }, 278 ... 279 }; 280 281 static const struct snd_soc_component_driver 282 ... 283 .dapm_widgets = wm2000_dapm_ 284 .num_dapm_widgets = ARRAY_SIZE(w 285 .dapm_routes = wm2000_audio 286 .num_dapm_routes = ARRAY_SIZE(w 287 ... 288 }; 289 290 In more complex cases the list of DAPM widgets 291 known at probe time. This happens for example 292 different models having a different set of fea 293 separate widgets and routes arrays implementin 294 can be registered programmatically by calling 295 and snd_soc_dapm_add_routes(). 296 297 298 Codec/DSP Widget Interconnections 299 ================================= 300 301 Widgets are connected to each other within the 302 audio paths (called interconnections). Each in 303 order to create a graph of all audio paths bet 304 305 This is easiest with a diagram of the codec or 306 audio system), as it requires joining widgets 307 paths. 308 309 For example the WM8731 output mixer (wm8731.c) 310 311 1. Line Bypass Input 312 2. DAC (HiFi playback) 313 3. Mic Sidetone Input 314 315 Each input in this example has a kcontrol asso 316 the example above) and is connected to the out 317 name. We can now connect the destination widge 318 source widgets. :: 319 320 /* output mixer */ 321 {"Output Mixer", "Line Bypass Switch", 322 {"Output Mixer", "HiFi Playback Switch 323 {"Output Mixer", "Mic Sidetone Switch" 324 325 So we have: 326 327 * Destination Widget <=== Path Name <=== Sour 328 * Sink, Path, Source, or 329 * ``Output Mixer`` is connected to the ``DAC`` 330 331 When there is no path name connecting widgets 332 pass NULL for the path name. 333 334 Interconnections are created with a call to:: 335 336 snd_soc_dapm_connect_input(codec, sink, path 337 338 Finally, snd_soc_dapm_new_widgets() must be ca 339 interconnections have been registered with the 340 scan the codec and machine so that the interna 341 physical state of the machine. 342 343 344 Machine Widget Interconnections 345 ------------------------------- 346 Machine widget interconnections are created in 347 directly connect the codec pins to machine lev 348 349 e.g. connects the speaker out codec pins to th 350 :: 351 352 /* ext speaker connected to codec pins 353 {"Ext Spk", NULL , "ROUT2"}, 354 {"Ext Spk", NULL , "LOUT2"}, 355 356 This allows the DAPM to power on and off pins 357 and pins that are NC respectively. 358 359 360 Endpoint Widgets 361 ================ 362 An endpoint is a start or end point (widget) o 363 machine and includes the codec. e.g. 364 365 * Headphone Jack 366 * Internal Speaker 367 * Internal Mic 368 * Mic Jack 369 * Codec Pins 370 371 Endpoints are added to the DAPM graph so that 372 order to save power. e.g. NC codecs pins will 373 jacks can also be switched OFF. 374 375 376 DAPM Widget Events 377 ================== 378 379 Widgets needing to implement a more complex be 380 can set a custom "event handler" by setting a 381 is a power supply needing to enable a GPIO:: 382 383 static int sof_es8316_speaker_power_event(st 384 stru 385 { 386 if (SND_SOC_DAPM_EVENT_ON(event)) 387 gpiod_set_value_cansleep(gpio_ 388 else 389 gpiod_set_value_cansleep(gpio_ 390 391 return 0; 392 } 393 394 static const struct snd_soc_dapm_widget st_w 395 ... 396 SND_SOC_DAPM_SUPPLY("Speaker Power", S 397 sof_es8316_speaker 398 SND_SOC_DAPM_PRE_P 399 }; 400 401 See soc-dapm.h for all other widgets that supp 402 403 404 Event types 405 ----------- 406 407 The following event types are supported by eve 408 409 /* dapm event types */ 410 #define SND_SOC_DAPM_PRE_PMU 0x1 411 #define SND_SOC_DAPM_POST_PMU 0x2 412 #define SND_SOC_DAPM_PRE_PMD 0x4 413 #define SND_SOC_DAPM_POST_PMD 0x8 414 #define SND_SOC_DAPM_PRE_REG 0x10 415 #define SND_SOC_DAPM_POST_REG 0x20 416 #define SND_SOC_DAPM_WILL_PMU 0x40 417 #define SND_SOC_DAPM_WILL_PMD 0x80 418 #define SND_SOC_DAPM_PRE_POST_PMD (SND_S 419 #define SND_SOC_DAPM_PRE_POST_PMU (SND_S
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.