Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  * linux/sound/soc-dapm.h -- ALSA SoC Dynamic Audio Power Management
0004  *
0005  * Author:  Liam Girdwood
0006  * Created: Aug 11th 2005
0007  * Copyright:   Wolfson Microelectronics. PLC.
0008  */
0009 
0010 #ifndef __LINUX_SND_SOC_DAPM_H
0011 #define __LINUX_SND_SOC_DAPM_H
0012 
0013 #include <linux/types.h>
0014 #include <sound/control.h>
0015 #include <sound/soc-topology.h>
0016 #include <sound/asoc.h>
0017 
0018 struct device;
0019 struct snd_soc_pcm_runtime;
0020 struct soc_enum;
0021 
0022 /* widget has no PM register bit */
0023 #define SND_SOC_NOPM    -1
0024 
0025 /*
0026  * SoC dynamic audio power management
0027  *
0028  * We can have up to 4 power domains
0029  *  1. Codec domain - VREF, VMID
0030  *     Usually controlled at codec probe/remove, although can be set
0031  *     at stream time if power is not needed for sidetone, etc.
0032  *  2. Platform/Machine domain - physically connected inputs and outputs
0033  *     Is platform/machine and user action specific, is set in the machine
0034  *     driver and by userspace e.g when HP are inserted
0035  *  3. Path domain - Internal codec path mixers
0036  *     Are automatically set when mixer and mux settings are
0037  *     changed by the user.
0038  *  4. Stream domain - DAC's and ADC's.
0039  *     Enabled when stream playback/capture is started.
0040  */
0041 
0042 /* codec domain */
0043 #define SND_SOC_DAPM_VMID(wname) \
0044 {   .id = snd_soc_dapm_vmid, .name = wname, .kcontrol_news = NULL, \
0045     .num_kcontrols = 0}
0046 
0047 /* platform domain */
0048 #define SND_SOC_DAPM_SIGGEN(wname) \
0049 {   .id = snd_soc_dapm_siggen, .name = wname, .kcontrol_news = NULL, \
0050     .num_kcontrols = 0, .reg = SND_SOC_NOPM }
0051 #define SND_SOC_DAPM_SINK(wname) \
0052 {   .id = snd_soc_dapm_sink, .name = wname, .kcontrol_news = NULL, \
0053     .num_kcontrols = 0, .reg = SND_SOC_NOPM }
0054 #define SND_SOC_DAPM_INPUT(wname) \
0055 {   .id = snd_soc_dapm_input, .name = wname, .kcontrol_news = NULL, \
0056     .num_kcontrols = 0, .reg = SND_SOC_NOPM }
0057 #define SND_SOC_DAPM_OUTPUT(wname) \
0058 {   .id = snd_soc_dapm_output, .name = wname, .kcontrol_news = NULL, \
0059     .num_kcontrols = 0, .reg = SND_SOC_NOPM }
0060 #define SND_SOC_DAPM_MIC(wname, wevent) \
0061 {   .id = snd_soc_dapm_mic, .name = wname, .kcontrol_news = NULL, \
0062     .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
0063     .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
0064 #define SND_SOC_DAPM_HP(wname, wevent) \
0065 {   .id = snd_soc_dapm_hp, .name = wname, .kcontrol_news = NULL, \
0066     .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
0067     .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
0068 #define SND_SOC_DAPM_SPK(wname, wevent) \
0069 {   .id = snd_soc_dapm_spk, .name = wname, .kcontrol_news = NULL, \
0070     .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
0071     .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
0072 #define SND_SOC_DAPM_LINE(wname, wevent) \
0073 {   .id = snd_soc_dapm_line, .name = wname, .kcontrol_news = NULL, \
0074     .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
0075     .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD}
0076 
0077 #define SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) \
0078     .reg = wreg, .mask = 1, .shift = wshift, \
0079     .on_val = winvert ? 0 : 1, .off_val = winvert ? 1 : 0
0080 
0081 /* path domain */
0082 #define SND_SOC_DAPM_PGA(wname, wreg, wshift, winvert,\
0083      wcontrols, wncontrols) \
0084 {   .id = snd_soc_dapm_pga, .name = wname, \
0085     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0086     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
0087 #define SND_SOC_DAPM_OUT_DRV(wname, wreg, wshift, winvert,\
0088      wcontrols, wncontrols) \
0089 {   .id = snd_soc_dapm_out_drv, .name = wname, \
0090     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0091     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
0092 #define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
0093      wcontrols, wncontrols)\
0094 {   .id = snd_soc_dapm_mixer, .name = wname, \
0095     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0096     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
0097 #define SND_SOC_DAPM_MIXER_NAMED_CTL(wname, wreg, wshift, winvert, \
0098      wcontrols, wncontrols)\
0099 {       .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
0100     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0101     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols}
0102 /* DEPRECATED: use SND_SOC_DAPM_SUPPLY */
0103 #define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
0104 {   .id = snd_soc_dapm_micbias, .name = wname, \
0105     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0106     .kcontrol_news = NULL, .num_kcontrols = 0}
0107 #define SND_SOC_DAPM_SWITCH(wname, wreg, wshift, winvert, wcontrols) \
0108 {   .id = snd_soc_dapm_switch, .name = wname, \
0109     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0110     .kcontrol_news = wcontrols, .num_kcontrols = 1}
0111 #define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
0112 {   .id = snd_soc_dapm_mux, .name = wname, \
0113     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0114     .kcontrol_news = wcontrols, .num_kcontrols = 1}
0115 #define SND_SOC_DAPM_DEMUX(wname, wreg, wshift, winvert, wcontrols) \
0116 {   .id = snd_soc_dapm_demux, .name = wname, \
0117     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0118     .kcontrol_news = wcontrols, .num_kcontrols = 1}
0119 
0120 /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
0121 #define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\
0122      wcontrols) \
0123 {   .id = snd_soc_dapm_pga, .name = wname, \
0124     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0125     .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
0126 #define SOC_MIXER_ARRAY(wname, wreg, wshift, winvert, \
0127      wcontrols)\
0128 {   .id = snd_soc_dapm_mixer, .name = wname, \
0129     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0130     .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
0131 #define SOC_MIXER_NAMED_CTL_ARRAY(wname, wreg, wshift, winvert, \
0132      wcontrols)\
0133 {       .id = snd_soc_dapm_mixer_named_ctl, .name = wname, \
0134     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0135     .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols)}
0136 
0137 /* path domain with event - event handler must return 0 for success */
0138 #define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
0139     wncontrols, wevent, wflags) \
0140 {   .id = snd_soc_dapm_pga, .name = wname, \
0141     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0142     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
0143     .event = wevent, .event_flags = wflags}
0144 #define SND_SOC_DAPM_OUT_DRV_E(wname, wreg, wshift, winvert, wcontrols, \
0145     wncontrols, wevent, wflags) \
0146 {   .id = snd_soc_dapm_out_drv, .name = wname, \
0147     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0148     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
0149     .event = wevent, .event_flags = wflags}
0150 #define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
0151     wncontrols, wevent, wflags) \
0152 {   .id = snd_soc_dapm_mixer, .name = wname, \
0153     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0154     .kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
0155     .event = wevent, .event_flags = wflags}
0156 #define SND_SOC_DAPM_MIXER_NAMED_CTL_E(wname, wreg, wshift, winvert, \
0157     wcontrols, wncontrols, wevent, wflags) \
0158 {       .id = snd_soc_dapm_mixer, .name = wname, \
0159     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0160     .kcontrol_news = wcontrols, \
0161     .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags}
0162 #define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
0163     wevent, wflags) \
0164 {   .id = snd_soc_dapm_switch, .name = wname, \
0165     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0166     .kcontrol_news = wcontrols, .num_kcontrols = 1, \
0167     .event = wevent, .event_flags = wflags}
0168 #define SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
0169     wevent, wflags) \
0170 {   .id = snd_soc_dapm_mux, .name = wname, \
0171     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0172     .kcontrol_news = wcontrols, .num_kcontrols = 1, \
0173     .event = wevent, .event_flags = wflags}
0174 
0175 /* additional sequencing control within an event type */
0176 #define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \
0177     wevent, wflags) \
0178 {   .id = snd_soc_dapm_pga, .name = wname, \
0179     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0180     .event = wevent, .event_flags = wflags, \
0181     .subseq = wsubseq}
0182 #define SND_SOC_DAPM_SUPPLY_S(wname, wsubseq, wreg, wshift, winvert, wevent, \
0183     wflags) \
0184 {   .id = snd_soc_dapm_supply, .name = wname, \
0185     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0186     .event = wevent, .event_flags = wflags, .subseq = wsubseq}
0187 
0188 /* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
0189 #define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
0190     wevent, wflags) \
0191 {   .id = snd_soc_dapm_pga, .name = wname, \
0192     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0193     .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
0194     .event = wevent, .event_flags = wflags}
0195 #define SOC_MIXER_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
0196     wevent, wflags) \
0197 {   .id = snd_soc_dapm_mixer, .name = wname, \
0198     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0199     .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
0200     .event = wevent, .event_flags = wflags}
0201 #define SOC_MIXER_NAMED_CTL_E_ARRAY(wname, wreg, wshift, winvert, \
0202     wcontrols, wevent, wflags) \
0203 {       .id = snd_soc_dapm_mixer, .name = wname, \
0204     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0205     .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols), \
0206     .event = wevent, .event_flags = wflags}
0207 
0208 /* events that are pre and post DAPM */
0209 #define SND_SOC_DAPM_PRE(wname, wevent) \
0210 {   .id = snd_soc_dapm_pre, .name = wname, .kcontrol_news = NULL, \
0211     .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
0212     .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD}
0213 #define SND_SOC_DAPM_POST(wname, wevent) \
0214 {   .id = snd_soc_dapm_post, .name = wname, .kcontrol_news = NULL, \
0215     .num_kcontrols = 0, .reg = SND_SOC_NOPM, .event = wevent, \
0216     .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD}
0217 
0218 /* stream domain */
0219 #define SND_SOC_DAPM_AIF_IN(wname, stname, wchan, wreg, wshift, winvert) \
0220 {   .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
0221     .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
0222 #define SND_SOC_DAPM_AIF_IN_E(wname, stname, wchan, wreg, wshift, winvert, \
0223                   wevent, wflags)               \
0224 {   .id = snd_soc_dapm_aif_in, .name = wname, .sname = stname, \
0225     .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0226     .event = wevent, .event_flags = wflags }
0227 #define SND_SOC_DAPM_AIF_OUT(wname, stname, wchan, wreg, wshift, winvert) \
0228 {   .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
0229     .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
0230 #define SND_SOC_DAPM_AIF_OUT_E(wname, stname, wchan, wreg, wshift, winvert, \
0231                  wevent, wflags)                \
0232 {   .id = snd_soc_dapm_aif_out, .name = wname, .sname = stname, \
0233     .channel = wchan, SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0234     .event = wevent, .event_flags = wflags }
0235 #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \
0236 {   .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
0237     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) }
0238 #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \
0239                wevent, wflags)              \
0240 {   .id = snd_soc_dapm_dac, .name = wname, .sname = stname, \
0241     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0242     .event = wevent, .event_flags = wflags}
0243 
0244 #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \
0245 {   .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
0246     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), }
0247 #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \
0248                wevent, wflags)              \
0249 {   .id = snd_soc_dapm_adc, .name = wname, .sname = stname, \
0250     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0251     .event = wevent, .event_flags = wflags}
0252 #define SND_SOC_DAPM_CLOCK_SUPPLY(wname) \
0253 {   .id = snd_soc_dapm_clock_supply, .name = wname, \
0254     .reg = SND_SOC_NOPM, .event = dapm_clock_event, \
0255     .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
0256 
0257 /* generic widgets */
0258 #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
0259 {   .id = wid, .name = wname, .kcontrol_news = NULL, .num_kcontrols = 0, \
0260     .reg = wreg, .shift = wshift, .mask = wmask, \
0261     .on_val = won_val, .off_val = woff_val, }
0262 #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \
0263 {   .id = snd_soc_dapm_supply, .name = wname, \
0264     SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
0265     .event = wevent, .event_flags = wflags}
0266 #define SND_SOC_DAPM_REGULATOR_SUPPLY(wname, wdelay, wflags)        \
0267 {   .id = snd_soc_dapm_regulator_supply, .name = wname, \
0268     .reg = SND_SOC_NOPM, .shift = wdelay, .event = dapm_regulator_event, \
0269     .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \
0270     .on_val = wflags}
0271 #define SND_SOC_DAPM_PINCTRL(wname, active, sleep) \
0272 {   .id = snd_soc_dapm_pinctrl, .name = wname, \
0273     .priv = (&(struct snd_soc_dapm_pinctrl_priv) \
0274         { .active_state = active, .sleep_state = sleep,}), \
0275     .reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \
0276     .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
0277 
0278 
0279 
0280 /* dapm kcontrol types */
0281 #define SOC_DAPM_DOUBLE(xname, reg, lshift, rshift, max, invert) \
0282 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0283     .info = snd_soc_info_volsw, \
0284     .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
0285     .private_value = SOC_DOUBLE_VALUE(reg, lshift, rshift, max, invert, 0) }
0286 #define SOC_DAPM_DOUBLE_R(xname, lreg, rreg, shift, max, invert) \
0287 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0288     .info = snd_soc_info_volsw, \
0289     .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
0290     .private_value = SOC_DOUBLE_R_VALUE(lreg, rreg, shift, max, invert) }
0291 #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
0292 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0293     .info = snd_soc_info_volsw, \
0294     .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
0295     .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
0296 #define SOC_DAPM_SINGLE_AUTODISABLE(xname, reg, shift, max, invert) \
0297 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0298     .info = snd_soc_info_volsw, \
0299     .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
0300     .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 1) }
0301 #define SOC_DAPM_SINGLE_VIRT(xname, max) \
0302     SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0)
0303 #define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
0304 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0305     .info = snd_soc_info_volsw, \
0306     .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
0307     .tlv.p = (tlv_array), \
0308     .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
0309     .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
0310 #define SOC_DAPM_SINGLE_TLV_AUTODISABLE(xname, reg, shift, max, invert, tlv_array) \
0311 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0312     .info = snd_soc_info_volsw, \
0313     .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
0314     .tlv.p = (tlv_array), \
0315     .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
0316     .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 1) }
0317 #define SOC_DAPM_SINGLE_TLV_VIRT(xname, max, tlv_array) \
0318     SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0, tlv_array)
0319 #define SOC_DAPM_ENUM(xname, xenum) \
0320 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0321     .info = snd_soc_info_enum_double, \
0322     .get = snd_soc_dapm_get_enum_double, \
0323     .put = snd_soc_dapm_put_enum_double, \
0324     .private_value = (unsigned long)&xenum }
0325 #define SOC_DAPM_ENUM_EXT(xname, xenum, xget, xput) \
0326 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
0327     .info = snd_soc_info_enum_double, \
0328     .get = xget, \
0329     .put = xput, \
0330     .private_value = (unsigned long)&xenum }
0331 #define SOC_DAPM_PIN_SWITCH(xname) \
0332 {   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
0333     .info = snd_soc_dapm_info_pin_switch, \
0334     .get = snd_soc_dapm_get_pin_switch, \
0335     .put = snd_soc_dapm_put_pin_switch, \
0336     .private_value = (unsigned long)xname }
0337 
0338 /* dapm stream operations */
0339 #define SND_SOC_DAPM_STREAM_NOP         0x0
0340 #define SND_SOC_DAPM_STREAM_START       0x1
0341 #define SND_SOC_DAPM_STREAM_STOP        0x2
0342 #define SND_SOC_DAPM_STREAM_SUSPEND     0x4
0343 #define SND_SOC_DAPM_STREAM_RESUME      0x8
0344 #define SND_SOC_DAPM_STREAM_PAUSE_PUSH  0x10
0345 #define SND_SOC_DAPM_STREAM_PAUSE_RELEASE   0x20
0346 
0347 /* dapm event types */
0348 #define SND_SOC_DAPM_PRE_PMU    0x1     /* before widget power up */
0349 #define SND_SOC_DAPM_POST_PMU   0x2     /* after widget power up */
0350 #define SND_SOC_DAPM_PRE_PMD    0x4     /* before widget power down */
0351 #define SND_SOC_DAPM_POST_PMD   0x8     /* after widget power down */
0352 #define SND_SOC_DAPM_PRE_REG    0x10    /* before audio path setup */
0353 #define SND_SOC_DAPM_POST_REG   0x20    /* after audio path setup */
0354 #define SND_SOC_DAPM_WILL_PMU   0x40    /* called at start of sequence */
0355 #define SND_SOC_DAPM_WILL_PMD   0x80    /* called at start of sequence */
0356 #define SND_SOC_DAPM_PRE_POST_PMD \
0357                 (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD)
0358 #define SND_SOC_DAPM_PRE_POST_PMU \
0359                 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU)
0360 
0361 /* convenience event type detection */
0362 #define SND_SOC_DAPM_EVENT_ON(e)    \
0363     (e & (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU))
0364 #define SND_SOC_DAPM_EVENT_OFF(e)   \
0365     (e & (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD))
0366 
0367 /* regulator widget flags */
0368 #define SND_SOC_DAPM_REGULATOR_BYPASS     0x1     /* bypass when disabled */
0369 
0370 struct snd_soc_dapm_widget;
0371 enum snd_soc_dapm_type;
0372 struct snd_soc_dapm_path;
0373 struct snd_soc_dapm_pin;
0374 struct snd_soc_dapm_route;
0375 struct snd_soc_dapm_context;
0376 struct regulator;
0377 struct snd_soc_dapm_widget_list;
0378 struct snd_soc_dapm_update;
0379 enum snd_soc_dapm_direction;
0380 
0381 /*
0382  * Bias levels
0383  *
0384  * @ON:      Bias is fully on for audio playback and capture operations.
0385  * @PREPARE: Prepare for audio operations. Called before DAPM switching for
0386  *           stream start and stop operations.
0387  * @STANDBY: Low power standby state when no playback/capture operations are
0388  *           in progress. NOTE: The transition time between STANDBY and ON
0389  *           should be as fast as possible and no longer than 10ms.
0390  * @OFF:     Power Off. No restrictions on transition times.
0391  */
0392 enum snd_soc_bias_level {
0393     SND_SOC_BIAS_OFF = 0,
0394     SND_SOC_BIAS_STANDBY = 1,
0395     SND_SOC_BIAS_PREPARE = 2,
0396     SND_SOC_BIAS_ON = 3,
0397 };
0398 
0399 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
0400              struct snd_kcontrol *kcontrol, int event);
0401 int dapm_clock_event(struct snd_soc_dapm_widget *w,
0402              struct snd_kcontrol *kcontrol, int event);
0403 int dapm_pinctrl_event(struct snd_soc_dapm_widget *w,
0404              struct snd_kcontrol *kcontrol, int event);
0405 
0406 /* dapm controls */
0407 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
0408     struct snd_ctl_elem_value *ucontrol);
0409 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
0410     struct snd_ctl_elem_value *ucontrol);
0411 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
0412     struct snd_ctl_elem_value *ucontrol);
0413 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
0414     struct snd_ctl_elem_value *ucontrol);
0415 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
0416     struct snd_ctl_elem_info *uinfo);
0417 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
0418     struct snd_ctl_elem_value *uncontrol);
0419 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
0420     struct snd_ctl_elem_value *uncontrol);
0421 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
0422     const struct snd_soc_dapm_widget *widget,
0423     int num);
0424 struct snd_soc_dapm_widget *snd_soc_dapm_new_control(
0425         struct snd_soc_dapm_context *dapm,
0426         const struct snd_soc_dapm_widget *widget);
0427 struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(
0428         struct snd_soc_dapm_context *dapm,
0429         const struct snd_soc_dapm_widget *widget);
0430 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
0431                  struct snd_soc_dai *dai);
0432 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
0433 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
0434 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
0435 
0436 int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
0437                 struct snd_pcm_hw_params *params,
0438                 struct snd_soc_dai *dai);
0439 
0440 /* dapm path setup */
0441 int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
0442 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm);
0443 void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm,
0444                struct snd_soc_card *card,
0445                struct snd_soc_component *component);
0446 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
0447                 const struct snd_soc_dapm_route *route, int num);
0448 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
0449                 const struct snd_soc_dapm_route *route, int num);
0450 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
0451                  const struct snd_soc_dapm_route *route, int num);
0452 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
0453 void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm);
0454 
0455 /* dapm events */
0456 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
0457     int event);
0458 void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream);
0459 void snd_soc_dapm_shutdown(struct snd_soc_card *card);
0460 
0461 /* external DAPM widget events */
0462 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
0463         struct snd_kcontrol *kcontrol, int connect,
0464         struct snd_soc_dapm_update *update);
0465 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm,
0466         struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e,
0467         struct snd_soc_dapm_update *update);
0468 
0469 /* dapm sys fs - used by the core */
0470 extern struct attribute *soc_dapm_dev_attrs[];
0471 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
0472                 struct dentry *parent);
0473 
0474 /* dapm audio pin control and status */
0475 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm,
0476                 const char *pin);
0477 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
0478                      const char *pin);
0479 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
0480                  const char *pin);
0481 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm,
0482                       const char *pin);
0483 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin);
0484 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
0485                  const char *pin);
0486 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
0487                 const char *pin);
0488 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
0489 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm);
0490 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
0491                   const char *pin);
0492 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
0493                        const char *pin);
0494 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
0495                 const char *pin);
0496 unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol);
0497 
0498 /* Mostly internal - should not normally be used */
0499 void dapm_mark_endpoints_dirty(struct snd_soc_card *card);
0500 
0501 /* dapm path query */
0502 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
0503     struct snd_soc_dapm_widget_list **list,
0504     bool (*custom_stop_condition)(struct snd_soc_dapm_widget *,
0505                       enum snd_soc_dapm_direction));
0506 void snd_soc_dapm_dai_free_widgets(struct snd_soc_dapm_widget_list **list);
0507 
0508 struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm(
0509     struct snd_kcontrol *kcontrol);
0510 
0511 struct snd_soc_dapm_widget *snd_soc_dapm_kcontrol_widget(
0512         struct snd_kcontrol *kcontrol);
0513 
0514 int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm,
0515     enum snd_soc_bias_level level);
0516 
0517 /* dapm widget types */
0518 enum snd_soc_dapm_type {
0519     snd_soc_dapm_input = 0,     /* input pin */
0520     snd_soc_dapm_output,        /* output pin */
0521     snd_soc_dapm_mux,           /* selects 1 analog signal from many inputs */
0522     snd_soc_dapm_demux,         /* connects the input to one of multiple outputs */
0523     snd_soc_dapm_mixer,         /* mixes several analog signals together */
0524     snd_soc_dapm_mixer_named_ctl,       /* mixer with named controls */
0525     snd_soc_dapm_pga,           /* programmable gain/attenuation (volume) */
0526     snd_soc_dapm_out_drv,           /* output driver */
0527     snd_soc_dapm_adc,           /* analog to digital converter */
0528     snd_soc_dapm_dac,           /* digital to analog converter */
0529     snd_soc_dapm_micbias,       /* microphone bias (power) - DEPRECATED: use snd_soc_dapm_supply */
0530     snd_soc_dapm_mic,           /* microphone */
0531     snd_soc_dapm_hp,            /* headphones */
0532     snd_soc_dapm_spk,           /* speaker */
0533     snd_soc_dapm_line,          /* line input/output */
0534     snd_soc_dapm_switch,        /* analog switch */
0535     snd_soc_dapm_vmid,          /* codec bias/vmid - to minimise pops */
0536     snd_soc_dapm_pre,           /* machine specific pre widget - exec first */
0537     snd_soc_dapm_post,          /* machine specific post widget - exec last */
0538     snd_soc_dapm_supply,        /* power/clock supply */
0539     snd_soc_dapm_pinctrl,       /* pinctrl */
0540     snd_soc_dapm_regulator_supply,  /* external regulator */
0541     snd_soc_dapm_clock_supply,  /* external clock */
0542     snd_soc_dapm_aif_in,        /* audio interface input */
0543     snd_soc_dapm_aif_out,       /* audio interface output */
0544     snd_soc_dapm_siggen,        /* signal generator */
0545     snd_soc_dapm_sink,
0546     snd_soc_dapm_dai_in,        /* link to DAI structure */
0547     snd_soc_dapm_dai_out,
0548     snd_soc_dapm_dai_link,      /* link between two DAI structures */
0549     snd_soc_dapm_kcontrol,      /* Auto-disabled kcontrol */
0550     snd_soc_dapm_buffer,        /* DSP/CODEC internal buffer */
0551     snd_soc_dapm_scheduler,     /* DSP/CODEC internal scheduler */
0552     snd_soc_dapm_effect,        /* DSP/CODEC effect component */
0553     snd_soc_dapm_src,       /* DSP/CODEC SRC component */
0554     snd_soc_dapm_asrc,      /* DSP/CODEC ASRC component */
0555     snd_soc_dapm_encoder,       /* FW/SW audio encoder component */
0556     snd_soc_dapm_decoder,       /* FW/SW audio decoder component */
0557 
0558     /* Don't edit below this line */
0559     SND_SOC_DAPM_TYPE_COUNT
0560 };
0561 
0562 enum snd_soc_dapm_subclass {
0563     SND_SOC_DAPM_CLASS_INIT     = 0,
0564     SND_SOC_DAPM_CLASS_RUNTIME  = 1,
0565 };
0566 
0567 /*
0568  * DAPM audio route definition.
0569  *
0570  * Defines an audio route originating at source via control and finishing
0571  * at sink.
0572  */
0573 struct snd_soc_dapm_route {
0574     const char *sink;
0575     const char *control;
0576     const char *source;
0577 
0578     /* Note: currently only supported for links where source is a supply */
0579     int (*connected)(struct snd_soc_dapm_widget *source,
0580              struct snd_soc_dapm_widget *sink);
0581 
0582     struct snd_soc_dobj dobj;
0583 };
0584 
0585 /* dapm audio path between two widgets */
0586 struct snd_soc_dapm_path {
0587     const char *name;
0588 
0589     /*
0590      * source (input) and sink (output) widgets
0591      * The union is for convience, since it is a lot nicer to type
0592      * p->source, rather than p->node[SND_SOC_DAPM_DIR_IN]
0593      */
0594     union {
0595         struct {
0596             struct snd_soc_dapm_widget *source;
0597             struct snd_soc_dapm_widget *sink;
0598         };
0599         struct snd_soc_dapm_widget *node[2];
0600     };
0601 
0602     /* status */
0603     u32 connect:1;  /* source and sink widgets are connected */
0604     u32 walking:1;  /* path is in the process of being walked */
0605     u32 weak:1; /* path ignored for power management */
0606     u32 is_supply:1;    /* At least one of the connected widgets is a supply */
0607 
0608     int (*connected)(struct snd_soc_dapm_widget *source,
0609              struct snd_soc_dapm_widget *sink);
0610 
0611     struct list_head list_node[2];
0612     struct list_head list_kcontrol;
0613     struct list_head list;
0614 };
0615 
0616 /* dapm widget */
0617 struct snd_soc_dapm_widget {
0618     enum snd_soc_dapm_type id;
0619     const char *name;       /* widget name */
0620     const char *sname;  /* stream name */
0621     struct list_head list;
0622     struct snd_soc_dapm_context *dapm;
0623 
0624     void *priv;             /* widget specific data */
0625     struct regulator *regulator;        /* attached regulator */
0626     struct pinctrl *pinctrl;        /* attached pinctrl */
0627 
0628     /* dapm control */
0629     int reg;                /* negative reg = no direct dapm */
0630     unsigned char shift;            /* bits to shift */
0631     unsigned int mask;          /* non-shifted mask */
0632     unsigned int on_val;            /* on state value */
0633     unsigned int off_val;           /* off state value */
0634     unsigned char power:1;          /* block power status */
0635     unsigned char active:1;         /* active stream on DAC, ADC's */
0636     unsigned char connected:1;      /* connected codec pin */
0637     unsigned char new:1;            /* cnew complete */
0638     unsigned char force:1;          /* force state */
0639     unsigned char ignore_suspend:1;         /* kept enabled over suspend */
0640     unsigned char new_power:1;      /* power from this run */
0641     unsigned char power_checked:1;      /* power checked this run */
0642     unsigned char is_supply:1;      /* Widget is a supply type widget */
0643     unsigned char is_ep:2;          /* Widget is a endpoint type widget */
0644     int subseq;             /* sort within widget type */
0645 
0646     int (*power_check)(struct snd_soc_dapm_widget *w);
0647 
0648     /* external events */
0649     unsigned short event_flags;     /* flags to specify event types */
0650     int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int);
0651 
0652     /* kcontrols that relate to this widget */
0653     int num_kcontrols;
0654     const struct snd_kcontrol_new *kcontrol_news;
0655     struct snd_kcontrol **kcontrols;
0656     struct snd_soc_dobj dobj;
0657 
0658     /* widget input and output edges */
0659     struct list_head edges[2];
0660 
0661     /* used during DAPM updates */
0662     struct list_head work_list;
0663     struct list_head power_list;
0664     struct list_head dirty;
0665     int endpoints[2];
0666 
0667     struct clk *clk;
0668 
0669     int channel;
0670 };
0671 
0672 struct snd_soc_dapm_update {
0673     struct snd_kcontrol *kcontrol;
0674     int reg;
0675     int mask;
0676     int val;
0677     int reg2;
0678     int mask2;
0679     int val2;
0680     bool has_second_set;
0681 };
0682 
0683 struct snd_soc_dapm_wcache {
0684     struct snd_soc_dapm_widget *widget;
0685 };
0686 
0687 /* DAPM context */
0688 struct snd_soc_dapm_context {
0689     enum snd_soc_bias_level bias_level;
0690     unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */
0691     /* Go to BIAS_OFF in suspend if the DAPM context is idle */
0692     unsigned int suspend_bias_off:1;
0693 
0694     struct device *dev; /* from parent - for debug */
0695     struct snd_soc_component *component; /* parent component */
0696     struct snd_soc_card *card; /* parent card */
0697 
0698     /* used during DAPM updates */
0699     enum snd_soc_bias_level target_bias_level;
0700     struct list_head list;
0701 
0702     struct snd_soc_dapm_wcache path_sink_cache;
0703     struct snd_soc_dapm_wcache path_source_cache;
0704 
0705 #ifdef CONFIG_DEBUG_FS
0706     struct dentry *debugfs_dapm;
0707 #endif
0708 };
0709 
0710 /* A list of widgets associated with an object, typically a snd_kcontrol */
0711 struct snd_soc_dapm_widget_list {
0712     int num_widgets;
0713     struct snd_soc_dapm_widget *widgets[];
0714 };
0715 
0716 #define for_each_dapm_widgets(list, i, widget)              \
0717     for ((i) = 0;                           \
0718          (i) < list->num_widgets && (widget = list->widgets[i]);    \
0719          (i)++)
0720 
0721 struct snd_soc_dapm_stats {
0722     int power_checks;
0723     int path_checks;
0724     int neighbour_checks;
0725 };
0726 
0727 struct snd_soc_dapm_pinctrl_priv {
0728     const char *active_state;
0729     const char *sleep_state;
0730 };
0731 
0732 /**
0733  * snd_soc_dapm_init_bias_level() - Initialize DAPM bias level
0734  * @dapm: The DAPM context to initialize
0735  * @level: The DAPM level to initialize to
0736  *
0737  * This function only sets the driver internal state of the DAPM level and will
0738  * not modify the state of the device. Hence it should not be used during normal
0739  * operation, but only to synchronize the internal state to the device state.
0740  * E.g. during driver probe to set the DAPM level to the one corresponding with
0741  * the power-on reset state of the device.
0742  *
0743  * To change the DAPM state of the device use snd_soc_dapm_set_bias_level().
0744  */
0745 static inline void snd_soc_dapm_init_bias_level(
0746     struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
0747 {
0748     dapm->bias_level = level;
0749 }
0750 
0751 /**
0752  * snd_soc_dapm_get_bias_level() - Get current DAPM bias level
0753  * @dapm: The context for which to get the bias level
0754  *
0755  * Returns: The current bias level of the passed DAPM context.
0756  */
0757 static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(
0758     struct snd_soc_dapm_context *dapm)
0759 {
0760     return dapm->bias_level;
0761 }
0762 
0763 enum snd_soc_dapm_direction {
0764     SND_SOC_DAPM_DIR_IN,
0765     SND_SOC_DAPM_DIR_OUT
0766 };
0767 
0768 #define SND_SOC_DAPM_DIR_TO_EP(x) BIT(x)
0769 
0770 #define SND_SOC_DAPM_EP_SOURCE SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_IN)
0771 #define SND_SOC_DAPM_EP_SINK SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_OUT)
0772 
0773 /**
0774  * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths in the
0775  *   specified direction of a widget
0776  * @w: The widget
0777  * @dir: Whether to iterate over the paths where the specified widget is the
0778  *       incoming or outgoing widgets
0779  * @p: The path iterator variable
0780  */
0781 #define snd_soc_dapm_widget_for_each_path(w, dir, p) \
0782     list_for_each_entry(p, &w->edges[dir], list_node[dir])
0783 
0784 /**
0785  * snd_soc_dapm_widget_for_each_sink_path_safe - Iterates over all paths in the
0786  *   specified direction of a widget
0787  * @w: The widget
0788  * @dir: Whether to iterate over the paths where the specified widget is the
0789  *       incoming or outgoing widgets
0790  * @p: The path iterator variable
0791  * @next_p: Temporary storage for the next path
0792  *
0793  *  This function works like snd_soc_dapm_widget_for_each_sink_path, expect that
0794  *  it is safe to remove the current path from the list while iterating
0795  */
0796 #define snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p) \
0797     list_for_each_entry_safe(p, next_p, &w->edges[dir], list_node[dir])
0798 
0799 /**
0800  * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths leaving a
0801  *  widget
0802  * @w: The widget
0803  * @p: The path iterator variable
0804  */
0805 #define snd_soc_dapm_widget_for_each_sink_path(w, p) \
0806     snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_IN, p)
0807 
0808 /**
0809  * snd_soc_dapm_widget_for_each_source_path - Iterates over all paths leading to
0810  *  a widget
0811  * @w: The widget
0812  * @p: The path iterator variable
0813  */
0814 #define snd_soc_dapm_widget_for_each_source_path(w, p) \
0815     snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_OUT, p)
0816 
0817 #endif