Add API snd_soc_get_volsw_clamped to read the volume from device. This similar to existing API snd_soc_get_volsw. But has additional step to clamp the value to max value if the register value is larger than max value.
Signed-off-by: Niranjan H Y niranjan.hy@ti.com --- include/sound/soc.h | 2 ++ sound/soc/soc-ops.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 1fffef311..34a490ece 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -553,6 +553,8 @@ int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol, #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); +int snd_soc_get_volsw_clamped(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); #define snd_soc_get_volsw_2r snd_soc_get_volsw diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 59e91741b..4d1ee5cd2 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -354,6 +354,28 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, } EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
+/** + * snd_soc_get_volsw_clamped - single mixer get callback with range + * @kcontrol: mixer control + * @ucontrol: control element information + * + * Similar to snd_soc_get_volsw, with additional operation to + * clamp the register value to its maximum. + * + * Returns 0 for success. + */ +int snd_soc_get_volsw_clamped(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; + unsigned int mask = soc_mixer_mask(mc); + + return soc_get_volsw(kcontrol, ucontrol, mc, mask, + mc->max - mc->min, true); +} +EXPORT_SYMBOL_GPL(snd_soc_get_volsw_clamped); + /** * snd_soc_put_volsw - single mixer put callback with range * @kcontrol: mixer control