aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@nokia.com>2010-05-07 07:05:49 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-05-07 11:41:33 -0400
commit637d3847ba0ca2c7780e6521cbe75568d19ff0db (patch)
tree6a9b76e2d0365cabba43f7a273feceb66710bf4c /sound
parent305787649826d6c84a6f9f71bc3318460610aba4 (diff)
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. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/soc-core.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index d59076e2ca84..4079223203eb 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2238,6 +2238,45 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2238EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2238EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2239 2239
2240/** 2240/**
2241 * snd_soc_limit_volume - Set new limit to an existing volume control.
2242 *
2243 * @codec: where to look for the control
2244 * @name: Name of the control
2245 * @max: new maximum limit
2246 *
2247 * Return 0 for success, else error.
2248 */
2249int snd_soc_limit_volume(struct snd_soc_codec *codec,
2250 const char *name, int max)
2251{
2252 struct snd_card *card = codec->card;
2253 struct snd_kcontrol *kctl;
2254 struct soc_mixer_control *mc;
2255 int found = 0;
2256 int ret = -EINVAL;
2257
2258 /* Sanity check for name and max */
2259 if (unlikely(!name || max <= 0))
2260 return -EINVAL;
2261
2262 list_for_each_entry(kctl, &card->controls, list) {
2263 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2264 found = 1;
2265 break;
2266 }
2267 }
2268 if (found) {
2269 mc = (struct soc_mixer_control *)kctl->private_value;
2270 if (max <= mc->max) {
2271 mc->max = max;
2272 ret = 0;
2273 }
2274 }
2275 return ret;
2276}
2277EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2278
2279/**
2241 * snd_soc_dai_set_sysclk - configure DAI system or master clock. 2280 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2242 * @dai: DAI 2281 * @dai: DAI
2243 * @clk_id: DAI specific clock ID 2282 * @clk_id: DAI specific clock ID