aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2015-10-18 09:39:16 -0400
committerTakashi Iwai <tiwai@suse.de>2015-10-21 08:24:14 -0400
commitbc1043cdcd84cb441d80cfd79ae4325218f6f9ba (patch)
tree3f7415ac850fc01cbf07fd0c3ad53860201306d7
parent7379047d5585187d1288486d4627873170d0005a (diff)
ALSA: Add helper function to add single value constraint
The recommended and most efficient way to constraint a configuration parameter to a single value is to set the minimum and maximum allowed values to the same value, i.e. calling snd_pcm_hw_constraint_minmax() with the same value for min and max. It is not necessarily obvious though that this is the approach that should be taken and some drivers have come up with other ways of solving this problem, e.g. installing a list constraint with a single item. List constraints are dynamic constraints though and hence less efficient than the static min-max constraint. This patch introduces a new helper function called snd_pcm_hw_constraint_single() which only takes a single value has the same effect as calling snd_pcm_hw_constraint_minmax() with the same values for min and max. But it is hopefully semantically more expressive, making it clear that this is the preferred way of setting a single value constraint. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Mark Brown <broonie@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--include/sound/pcm.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 691e7ee0a510..04fbcba9290b 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -1034,6 +1034,22 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
1034 snd_pcm_hw_rule_func_t func, void *private, 1034 snd_pcm_hw_rule_func_t func, void *private,
1035 int dep, ...); 1035 int dep, ...);
1036 1036
1037/**
1038 * snd_pcm_hw_constraint_single() - Constrain parameter to a single value
1039 * @runtime: PCM runtime instance
1040 * @var: The hw_params variable to constrain
1041 * @val: The value to constrain to
1042 *
1043 * Return: Positive if the value is changed, zero if it's not changed, or a
1044 * negative error code.
1045 */
1046static inline int snd_pcm_hw_constraint_single(
1047 struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
1048 unsigned int val)
1049{
1050 return snd_pcm_hw_constraint_minmax(runtime, var, val, val);
1051}
1052
1037int snd_pcm_format_signed(snd_pcm_format_t format); 1053int snd_pcm_format_signed(snd_pcm_format_t format);
1038int snd_pcm_format_unsigned(snd_pcm_format_t format); 1054int snd_pcm_format_unsigned(snd_pcm_format_t format);
1039int snd_pcm_format_linear(snd_pcm_format_t format); 1055int snd_pcm_format_linear(snd_pcm_format_t format);