Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) ===================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) Dynamic Audio Power Management for Portable Devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) ===================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) Dynamic Audio Power Management (DAPM) is designed to allow portable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) Linux devices to use the minimum amount of power within the audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) subsystem at all times. It is independent of other kernel PM and as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) such, can easily co-exist with the other PM systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) DAPM is also completely transparent to all user space applications as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) all power switching is done within the ASoC core. No code changes or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) recompiling are required for user space applications. DAPM makes power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) switching decisions based upon any audio stream (capture/playback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) activity and audio mixer settings within the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) DAPM spans the whole machine. It covers power control within the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) audio subsystem, this includes internal codec power blocks and machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) level power systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) There are 4 power domains within DAPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) Codec bias domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)       VREF, VMID (core codec and audio power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)       Usually controlled at codec probe/remove and suspend/resume, although
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)       can be set at stream time if power is not needed for sidetone, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) Platform/Machine domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)       physically connected inputs and outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)       Is platform/machine and user action specific, is configured by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)       machine driver and responds to asynchronous events e.g when HP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)       are inserted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) Path domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)       audio subsystem signal paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)       Automatically set when mixer and mux settings are changed by the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)       e.g. alsamixer, amixer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) Stream domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)       DACs and ADCs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)       Enabled and disabled when stream playback/capture is started and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)       stopped respectively. e.g. aplay, arecord.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) All DAPM power switching decisions are made automatically by consulting an audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) routing map of the whole machine. This map is specific to each machine and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) consists of the interconnections between every audio component (including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) internal codec components). All audio components that effect power are called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) widgets hereafter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) DAPM Widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) Audio DAPM widgets fall into a number of types:-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) Mixer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	Mixes several analog signals into a single analog signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) Mux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	An analog switch that outputs only one of many inputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) PGA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	A programmable gain amplifier or attenuation widget.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) ADC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	Analog to Digital Converter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) DAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	Digital to Analog Converter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) Switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	An analog switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) Input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	A codec input pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) Output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	A codec output pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) Headphone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	Headphone (and optional Jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) Mic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	Mic (and optional Jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) Line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	Line Input/Output (and optional Jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) Speaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	Speaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) Supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	Power or clock supply widget used by other widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) Regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	External regulator that supplies power to audio components.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) Clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	External clock that supplies clock to audio components.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) AIF IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	Audio Interface Input (with TDM slot mask).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) AIF OUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	Audio Interface Output (with TDM slot mask).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) Siggen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	Signal Generator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) DAI IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	Digital Audio Interface Input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) DAI OUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	Digital Audio Interface Output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) DAI Link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	DAI Link between two DAI structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) Pre
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	Special PRE widget (exec before all others)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) Post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	Special POST widget (exec after all others)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	Inter widget audio data buffer within a DSP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) Scheduler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	DSP internal scheduler that schedules component/pipeline processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) Effect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	Widget that performs an audio processing effect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) SRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	Sample Rate Converter within DSP or CODEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ASRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	Asynchronous Sample Rate Converter within DSP or CODEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) Encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	Widget that encodes audio data from one format (usually PCM) to another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	usually more compressed format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) Decoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	Widget that decodes audio data from a compressed format to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	uncompressed format like PCM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) (Widgets are defined in include/sound/soc-dapm.h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) Widgets can be added to the sound card by any of the component driver types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) There are convenience macros defined in soc-dapm.h that can be used to quickly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) build a list of widgets of the codecs and machines DAPM widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) Most widgets have a name, register, shift and invert. Some widgets have extra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) parameters for stream name and kcontrols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) Stream Domain Widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) Stream Widgets relate to the stream power domain and only consist of ADCs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) (analog to digital converters), DACs (digital to analog converters),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) AIF IN and AIF OUT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) Stream widgets have the following format:-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)   SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)   SND_SOC_DAPM_AIF_IN(name, stream, slot, reg, shift, invert)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) NOTE: the stream name must match the corresponding stream name in your codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) snd_soc_codec_dai.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) e.g. stream widgets for HiFi playback and capture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)   SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)   SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) e.g. stream widgets for AIF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)   SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)   SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) Path Domain Widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) -------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) Path domain widgets have a ability to control or affect the audio signal or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) audio paths within the audio subsystem. They have the following form:-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)   SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) Any widget kcontrols can be set using the controls and num_controls members.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) e.g. Mixer widget (the kcontrols are declared first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)   /* Output Mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)   static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)   SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)   SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)   SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)   };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)   SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ARRAY_SIZE(wm8731_output_mixer_controls)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) If you don't want the mixer elements prefixed with the name of the mixer widget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) as for SND_SOC_DAPM_MIXER.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) Machine domain Widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ----------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) Machine widgets are different from codec widgets in that they don't have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) codec register bit associated with them. A machine widget is assigned to each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) machine audio component (non codec or DSP) that can be independently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) powered. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * Speaker Amp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * Microphone Bias
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * Jack connectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) A machine widget can have an optional call back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) e.g. Jack connector widget for an external Mic that enables Mic Bias
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) when the Mic is inserted:-::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)   static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	gpio_set_value(SPITZ_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)   SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) Codec (BIAS) Domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) -------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) The codec bias power domain has no widgets and is handled by the codecs DAPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) event handler. This handler is called when the codec powerstate is changed wrt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) to any stream event or by kernel PM events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) Virtual Widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ---------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) Sometimes widgets exist in the codec or machine audio map that don't have any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) corresponding soft power control. In this case it is necessary to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) a virtual widget - a widget with no control bits e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)   SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) This can be used to merge to signal paths together in software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) After all the widgets have been defined, they can then be added to the DAPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) subsystem individually with a call to snd_soc_dapm_new_control().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) Codec/DSP Widget Interconnections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) Widgets are connected to each other within the codec, platform and machine by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) audio paths (called interconnections). Each interconnection must be defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) order to create a map of all audio paths between widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) This is easiest with a diagram of the codec or DSP (and schematic of the machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) audio system), as it requires joining widgets together via their audio signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) paths.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) e.g., from the WM8731 output mixer (wm8731.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) The WM8731 output mixer has 3 inputs (sources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 1. Line Bypass Input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 2. DAC (HiFi playback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 3. Mic Sidetone Input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) Each input in this example has a kcontrol associated with it (defined in example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) above) and is connected to the output mixer via its kcontrol name. We can now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) connect the destination widget (wrt audio signal) with its source widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	/* output mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	{"Output Mixer", "Line Bypass Switch", "Line Input"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	{"Output Mixer", "HiFi Playback Switch", "DAC"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	{"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) So we have :-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Destination Widget  <=== Path Name <=== Source Widget, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Sink, Path, Source, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * ``Output Mixer`` is connected to the ``DAC`` via the ``HiFi Playback Switch``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) When there is no path name connecting widgets (e.g. a direct connection) we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pass NULL for the path name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) Interconnections are created with a call to:-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)   snd_soc_dapm_connect_input(codec, sink, path, source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) interconnections have been registered with the core. This causes the core to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) scan the codec and machine so that the internal DAPM state matches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) physical state of the machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) Machine Widget Interconnections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) -------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) Machine widget interconnections are created in the same way as codec ones and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) directly connect the codec pins to machine level widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) e.g. connects the speaker out codec pins to the internal speaker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* ext speaker connected to codec pins LOUT2, ROUT2  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	{"Ext Spk", NULL , "ROUT2"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	{"Ext Spk", NULL , "LOUT2"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) This allows the DAPM to power on and off pins that are connected (and in use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) and pins that are NC respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) Endpoint Widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) An endpoint is a start or end point (widget) of an audio signal within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) machine and includes the codec. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * Headphone Jack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * Internal Speaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * Internal Mic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * Mic Jack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * Codec Pins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) Endpoints are added to the DAPM graph so that their usage can be determined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) order to save power. e.g. NC codecs pins will be switched OFF, unconnected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) jacks can also be switched OFF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) DAPM Widget Events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ==================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) Some widgets can register their interest with the DAPM core in PM events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) e.g. A Speaker with an amplifier registers a widget so the amplifier can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) powered only when the spk is in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)   /* turn speaker amplifier on/off depending on use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)   static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)   /* corgi machine dapm widgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)   static const struct snd_soc_dapm_widget wm8731_dapm_widgets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) Please see soc-dapm.h for all other widgets that support events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) Event types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) The following event types are supported by event widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)   /* dapm event types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)   #define SND_SOC_DAPM_PRE_PMU	0x1 	/* before widget power up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)   #define SND_SOC_DAPM_POST_PMU	0x2		/* after widget power up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)   #define SND_SOC_DAPM_PRE_PMD	0x4 	/* before widget power down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)   #define SND_SOC_DAPM_POST_PMD	0x8		/* after widget power down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)   #define SND_SOC_DAPM_PRE_REG	0x10	/* before audio path setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)   #define SND_SOC_DAPM_POST_REG	0x20	/* after audio path setup */