2016-11-11 05:19:33 +08:00
|
|
|
===================================================
|
2006-10-07 00:34:51 +08:00
|
|
|
Dynamic Audio Power Management for Portable Devices
|
|
|
|
===================================================
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Description
|
|
|
|
===========
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
Dynamic Audio Power Management (DAPM) is designed to allow portable
|
|
|
|
Linux devices to use the minimum amount of power within the audio
|
|
|
|
subsystem at all times. It is independent of other kernel PM and as
|
|
|
|
such, can easily co-exist with the other PM systems.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
DAPM is also completely transparent to all user space applications as
|
|
|
|
all power switching is done within the ASoC core. No code changes or
|
|
|
|
recompiling are required for user space applications. DAPM makes power
|
|
|
|
switching decisions based upon any audio stream (capture/playback)
|
|
|
|
activity and audio mixer settings within the device.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
DAPM spans the whole machine. It covers power control within the entire
|
|
|
|
audio subsystem, this includes internal codec power blocks and machine
|
|
|
|
level power systems.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
There are 4 power domains within DAPM
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Codec bias domain
|
|
|
|
VREF, VMID (core codec and audio power)
|
|
|
|
|
2006-10-07 00:34:51 +08:00
|
|
|
Usually controlled at codec probe/remove and suspend/resume, although
|
|
|
|
can be set at stream time if power is not needed for sidetone, etc.
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Platform/Machine domain
|
|
|
|
physically connected inputs and outputs
|
|
|
|
|
2006-10-07 00:34:51 +08:00
|
|
|
Is platform/machine and user action specific, is configured by the
|
|
|
|
machine driver and responds to asynchronous events e.g when HP
|
|
|
|
are inserted
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Path domain
|
|
|
|
audio subsystem signal paths
|
|
|
|
|
2006-10-07 00:34:51 +08:00
|
|
|
Automatically set when mixer and mux settings are changed by the user.
|
|
|
|
e.g. alsamixer, amixer.
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Stream domain
|
|
|
|
DACs and ADCs.
|
|
|
|
|
2006-10-07 00:34:51 +08:00
|
|
|
Enabled and disabled when stream playback/capture is started and
|
|
|
|
stopped respectively. e.g. aplay, arecord.
|
|
|
|
|
2007-10-20 07:34:40 +08:00
|
|
|
All DAPM power switching decisions are made automatically by consulting an audio
|
2006-10-07 00:34:51 +08:00
|
|
|
routing map of the whole machine. This map is specific to each machine and
|
|
|
|
consists of the interconnections between every audio component (including
|
|
|
|
internal codec components). All audio components that effect power are called
|
|
|
|
widgets hereafter.
|
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
DAPM Widgets
|
|
|
|
============
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Audio DAPM widgets fall into a number of types:-
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Mixer
|
|
|
|
Mixes several analog signals into a single analog signal.
|
|
|
|
Mux
|
|
|
|
An analog switch that outputs only one of many inputs.
|
|
|
|
PGA
|
|
|
|
A programmable gain amplifier or attenuation widget.
|
|
|
|
ADC
|
|
|
|
Analog to Digital Converter
|
|
|
|
DAC
|
|
|
|
Digital to Analog Converter
|
|
|
|
Switch
|
|
|
|
An analog switch
|
|
|
|
Input
|
|
|
|
A codec input pin
|
|
|
|
Output
|
|
|
|
A codec output pin
|
|
|
|
Headphone
|
|
|
|
Headphone (and optional Jack)
|
|
|
|
Mic
|
|
|
|
Mic (and optional Jack)
|
|
|
|
Line
|
|
|
|
Line Input/Output (and optional Jack)
|
|
|
|
Speaker
|
|
|
|
Speaker
|
|
|
|
Supply
|
|
|
|
Power or clock supply widget used by other widgets.
|
|
|
|
Regulator
|
|
|
|
External regulator that supplies power to audio components.
|
|
|
|
Clock
|
|
|
|
External clock that supplies clock to audio components.
|
|
|
|
AIF IN
|
|
|
|
Audio Interface Input (with TDM slot mask).
|
|
|
|
AIF OUT
|
|
|
|
Audio Interface Output (with TDM slot mask).
|
|
|
|
Siggen
|
|
|
|
Signal Generator.
|
|
|
|
DAI IN
|
|
|
|
Digital Audio Interface Input.
|
|
|
|
DAI OUT
|
|
|
|
Digital Audio Interface Output.
|
|
|
|
DAI Link
|
|
|
|
DAI Link between two DAI structures
|
|
|
|
Pre
|
|
|
|
Special PRE widget (exec before all others)
|
|
|
|
Post
|
|
|
|
Special POST widget (exec after all others)
|
2017-06-29 21:22:24 +08:00
|
|
|
Buffer
|
|
|
|
Inter widget audio data buffer within a DSP.
|
|
|
|
Scheduler
|
|
|
|
DSP internal scheduler that schedules component/pipeline processing
|
|
|
|
work.
|
|
|
|
Effect
|
|
|
|
Widget that performs an audio processing effect.
|
|
|
|
SRC
|
|
|
|
Sample Rate Converter within DSP or CODEC
|
|
|
|
ASRC
|
|
|
|
Asynchronous Sample Rate Converter within DSP or CODEC
|
|
|
|
Encoder
|
|
|
|
Widget that encodes audio data from one format (usually PCM) to another
|
|
|
|
usually more compressed format.
|
|
|
|
Decoder
|
|
|
|
Widget that decodes audio data from a compressed format to an
|
|
|
|
uncompressed format like PCM.
|
|
|
|
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
(Widgets are defined in include/sound/soc-dapm.h)
|
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
Widgets can be added to the sound card by any of the component driver types.
|
|
|
|
There are convenience macros defined in soc-dapm.h that can be used to quickly
|
|
|
|
build a list of widgets of the codecs and machines DAPM widgets.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Most widgets have a name, register, shift and invert. Some widgets have extra
|
|
|
|
parameters for stream name and kcontrols.
|
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Stream Domain Widgets
|
|
|
|
---------------------
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
Stream Widgets relate to the stream power domain and only consist of ADCs
|
2013-09-21 01:19:07 +08:00
|
|
|
(analog to digital converters), DACs (digital to analog converters),
|
|
|
|
AIF IN and AIF OUT.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Stream widgets have the following format:-
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),
|
|
|
|
SND_SOC_DAPM_AIF_IN(name, stream, slot, reg, shift, invert)
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
NOTE: the stream name must match the corresponding stream name in your codec
|
2006-10-07 00:34:51 +08:00
|
|
|
snd_soc_codec_dai.
|
|
|
|
|
|
|
|
e.g. stream widgets for HiFi playback and capture
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1),
|
|
|
|
SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
e.g. stream widgets for AIF
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2013-09-21 01:19:07 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
|
2013-09-21 01:19:07 +08:00
|
|
|
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Path Domain Widgets
|
|
|
|
-------------------
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
Path domain widgets have a ability to control or affect the audio signal or
|
2006-10-07 00:34:51 +08:00
|
|
|
audio paths within the audio subsystem. They have the following form:-
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Any widget kcontrols can be set using the controls and num_controls members.
|
|
|
|
|
|
|
|
e.g. Mixer widget (the kcontrols are declared first)
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
/* Output Mixer */
|
|
|
|
static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
|
|
|
|
SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
|
|
|
|
};
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
|
2006-10-07 00:34:51 +08:00
|
|
|
ARRAY_SIZE(wm8731_output_mixer_controls)),
|
|
|
|
|
2016-04-25 14:37:02 +08:00
|
|
|
If you don't want the mixer elements prefixed with the name of the mixer widget,
|
2009-01-07 04:11:51 +08:00
|
|
|
you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same
|
|
|
|
as for SND_SOC_DAPM_MIXER.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Machine domain Widgets
|
|
|
|
----------------------
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Machine widgets are different from codec widgets in that they don't have a
|
|
|
|
codec register bit associated with them. A machine widget is assigned to each
|
2013-09-21 01:19:07 +08:00
|
|
|
machine audio component (non codec or DSP) that can be independently
|
|
|
|
powered. e.g.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
* Speaker Amp
|
|
|
|
* Microphone Bias
|
|
|
|
* Jack connectors
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
A machine widget can have an optional call back.
|
|
|
|
|
|
|
|
e.g. Jack connector widget for an external Mic that enables Mic Bias
|
2016-11-11 05:19:33 +08:00
|
|
|
when the Mic is inserted:-::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event)
|
|
|
|
{
|
2008-09-19 02:15:08 +08:00
|
|
|
gpio_set_value(SPITZ_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event));
|
2006-10-07 00:34:51 +08:00
|
|
|
return 0;
|
2016-11-11 05:19:33 +08:00
|
|
|
}
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Codec (BIAS) Domain
|
|
|
|
-------------------
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
The codec bias power domain has no widgets and is handled by the codecs DAPM
|
|
|
|
event handler. This handler is called when the codec powerstate is changed wrt
|
|
|
|
to any stream event or by kernel PM events.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Virtual Widgets
|
|
|
|
---------------
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Sometimes widgets exist in the codec or machine audio map that don't have any
|
2008-01-23 15:41:46 +08:00
|
|
|
corresponding soft power control. In this case it is necessary to create
|
|
|
|
a virtual widget - a widget with no control bits e.g.
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
This can be used to merge to signal paths together in software.
|
|
|
|
|
|
|
|
After all the widgets have been defined, they can then be added to the DAPM
|
|
|
|
subsystem individually with a call to snd_soc_dapm_new_control().
|
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Codec/DSP Widget Interconnections
|
|
|
|
=================================
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
Widgets are connected to each other within the codec, platform and machine by
|
|
|
|
audio paths (called interconnections). Each interconnection must be defined in
|
|
|
|
order to create a map of all audio paths between widgets.
|
2008-01-23 15:41:46 +08:00
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
This is easiest with a diagram of the codec or DSP (and schematic of the machine
|
|
|
|
audio system), as it requires joining widgets together via their audio signal
|
|
|
|
paths.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2008-01-23 15:41:46 +08:00
|
|
|
e.g., from the WM8731 output mixer (wm8731.c)
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
The WM8731 output mixer has 3 inputs (sources)
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
1. Line Bypass Input
|
|
|
|
2. DAC (HiFi playback)
|
|
|
|
3. Mic Sidetone Input
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Each input in this example has a kcontrol associated with it (defined in example
|
2010-04-23 06:08:02 +08:00
|
|
|
above) and is connected to the output mixer via its kcontrol name. We can now
|
|
|
|
connect the destination widget (wrt audio signal) with its source widgets.
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
/* output mixer */
|
|
|
|
{"Output Mixer", "Line Bypass Switch", "Line Input"},
|
|
|
|
{"Output Mixer", "HiFi Playback Switch", "DAC"},
|
|
|
|
{"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
|
|
|
|
|
|
|
|
So we have :-
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
* Destination Widget <=== Path Name <=== Source Widget, or
|
|
|
|
* Sink, Path, Source, or
|
|
|
|
* ``Output Mixer`` is connected to the ``DAC`` via the ``HiFi Playback Switch``.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
When there is no path name connecting widgets (e.g. a direct connection) we
|
|
|
|
pass NULL for the path name.
|
|
|
|
|
|
|
|
Interconnections are created with a call to:-
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
snd_soc_dapm_connect_input(codec, sink, path, source);
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and
|
|
|
|
interconnections have been registered with the core. This causes the core to
|
|
|
|
scan the codec and machine so that the internal DAPM state matches the
|
|
|
|
physical state of the machine.
|
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Machine Widget Interconnections
|
|
|
|
-------------------------------
|
2006-10-07 00:34:51 +08:00
|
|
|
Machine widget interconnections are created in the same way as codec ones and
|
|
|
|
directly connect the codec pins to machine level widgets.
|
|
|
|
|
|
|
|
e.g. connects the speaker out codec pins to the internal speaker.
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
/* ext speaker connected to codec pins LOUT2, ROUT2 */
|
|
|
|
{"Ext Spk", NULL , "ROUT2"},
|
|
|
|
{"Ext Spk", NULL , "LOUT2"},
|
|
|
|
|
|
|
|
This allows the DAPM to power on and off pins that are connected (and in use)
|
|
|
|
and pins that are NC respectively.
|
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Endpoint Widgets
|
|
|
|
================
|
2006-10-07 00:34:51 +08:00
|
|
|
An endpoint is a start or end point (widget) of an audio signal within the
|
|
|
|
machine and includes the codec. e.g.
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
* Headphone Jack
|
|
|
|
* Internal Speaker
|
|
|
|
* Internal Mic
|
|
|
|
* Mic Jack
|
|
|
|
* Codec Pins
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2013-09-21 01:19:07 +08:00
|
|
|
Endpoints are added to the DAPM graph so that their usage can be determined in
|
|
|
|
order to save power. e.g. NC codecs pins will be switched OFF, unconnected
|
|
|
|
jacks can also be switched OFF.
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
DAPM Widget Events
|
|
|
|
==================
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
Some widgets can register their interest with the DAPM core in PM events.
|
|
|
|
e.g. A Speaker with an amplifier registers a widget so the amplifier can be
|
|
|
|
powered only when the spk is in use.
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
/* turn speaker amplifier on/off depending on use */
|
|
|
|
static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
|
|
|
|
{
|
2008-09-19 02:15:08 +08:00
|
|
|
gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event));
|
2006-10-07 00:34:51 +08:00
|
|
|
return 0;
|
2016-11-11 05:19:33 +08:00
|
|
|
}
|
2006-10-07 00:34:51 +08:00
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
/* corgi machine dapm widgets */
|
|
|
|
static const struct snd_soc_dapm_widget wm8731_dapm_widgets =
|
2006-10-07 00:34:51 +08:00
|
|
|
SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);
|
|
|
|
|
|
|
|
Please see soc-dapm.h for all other widgets that support events.
|
|
|
|
|
|
|
|
|
2016-11-11 05:19:33 +08:00
|
|
|
Event types
|
|
|
|
-----------
|
2006-10-07 00:34:51 +08:00
|
|
|
|
|
|
|
The following event types are supported by event widgets.
|
2016-11-11 05:19:33 +08:00
|
|
|
::
|
|
|
|
|
|
|
|
/* dapm event types */
|
|
|
|
#define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
|
|
|
|
#define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
|
|
|
|
#define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
|
|
|
|
#define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
|
|
|
|
#define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
|
|
|
|
#define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */
|