ASoC: core: Support for limiting the volume
PATCH 1/1 ASoC: core: Support for limiting the volume
Add support for the core to limit the maximum volume on an existing control.
The function will modify the soc_mixer_control.max value of the given control.
The new value must be lower than the original one (chip maximum)
If there is a need for limiting a gain on a given control, than machine drivers can do the following in their snd_soc_dai_link.init function:
snd_soc_limit_volume(codec, "TPA6140A2 Headphone Playback Volume", 21);
This will modify the original 31 (chip maximum) to 21, so user space will not be able to set the gain higher than this.
--- include/sound/soc.h | 2 ++ sound/soc/soc-core.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 0 deletions(-)
include/sound/soc.h +2 -0
@@ -326,6 +326,8 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);int snd_soc_put_volsw_s8 (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol); +int snd_soc_limit_volume (struct snd_soc_codec *codec, +const char *name,int max);/** * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
sound/soc/soc-core.c +39 -0
@@ -2238,6 +2238,45 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,EXPORT_SYMBOL_GPL (snd_soc_put_volsw_s8);/** +* snd_soc_limit_volume - Set new limit to an existing volume control. +* +* @codec: where to look for the control +* @name: Name of the control +* @max: new maximum limit +* +* Return 0 for success, else error. +*/ +int snd_soc_limit_volume (struct snd_soc_codec *codec, +const char *name,int max) +{ +struct snd_card *card = codec->card; +struct snd_kcontrol *kctl; +struct soc_mixer_control *mc; +int found =0 ; +int ret = -EINVAL ; + +/* Sanity check for name and max */ +if (unlikely (!name || max <=0 )) +return -EINVAL ; + +list_for_each_entry (kctl, &card->controls, list) { +if (!strncmp (kctl->id.name, name,sizeof (kctl->id.name))) { + found =1 ; +break ; + } + } +if (found) { + mc = (struct soc_mixer_control *)kctl->private_value; +if (max <= mc->max) { + mc->max = max; + ret =0 ; + } + } +return ret; +} +EXPORT_SYMBOL_GPL (snd_soc_limit_volume); + +/** * snd_soc_dai_set_sysclk - configure DAI system or master clock. * @dai: DAI * @clk_id: DAI specific clock ID
Signature · 1 line
1.7.1
Quoted 10 lines · Peter Ujfalusi
Add support for the core to limit the maximum volume on an existing control.
The function will modify the soc_mixer_control.max value of the given control.
The new value must be lower than the original one (chip maximum)If there is a need for limiting a gain on a given control, than machine drivers can do the following in their snd_soc_dai_link.init function:
Quoted 7 lines
snd_soc_limit_volume(codec, "TPA6140A2 Headphone Playback Volume", 21);This will modify the original 31 (chip maximum) to 21, so user space will not be able to set the gain higher than this.
Signed-off-by Peter Ujfalusi <[email protected]>---
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Mark Brown
AppliedQuoted 5 lines · Peter Ujfalusi
Add support for the core to limit the maximum volume on an existing control.
The function will modify the soc_mixer_control.max value of the given control.
The new value must be lower than the original one (chip maximum)
Applied, thanks.
Quoted 8 lines · On Friday 07 May 2010 18:41:20 ext Mark Brown wrote:
Quoted 5 lines · Peter Ujfalusi
Add support for the core to limit the maximum volume on an existing control.
The function will modify the soc_mixer_control.max value of the given control.
The new value must be lower than the original one (chip maximum)Applied, thanks.
Thanks,
however it seams that if the control has invert enabled this is going to break. In case of invert we need to invert from the chip maximum, and not from the platform dependent limit.
The only way I can think of to solve this is to introduce new variable in soc_mixer_control struct. It can be called platform_max.
The snd_soc_limit_volume would modify the platform_max leaving the max as configured by the drivers (chip maximum).
In volsw_info calls than we return the platform_max instead of max. If in the _info call the platform_max is 0, than we take the max to report (some custom kcontrol macro might not aware of the change in codec drivers).
What do you think?
Signature · 1 line
Péter
Quoted 11 lines · Peter Ujfalusi
however it seams that if the control has invert enabled this is going to break. In case of invert we need to invert from the chip maximum, and not from the platform dependent limit.
The only way I can think of to solve this is to introduce new variable insoc_mixer_controlstruct. It can be calledplatform_max.
Thesnd_soc_limit_volumewould modify theplatform_maxleaving the max as configured by the drivers (chip maximum).
Involsw_infocalls than we return theplatform_maxinstead of max. If in the_infocall theplatform_maxis 0, than we take the max to report (some custom kcontrol macro might not aware of the change in codec drivers).
Quoted 1 line
What do you think?
That sounds sensible enough.