aboutsummaryrefslogtreecommitdiffstats
path: root/include/sound
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-02-28 02:31:03 -0500
committerMark Brown <broonie@linaro.org>2014-02-28 22:03:33 -0500
commit29ae2fa5533e607a7d97b7564dc015252f1e73f4 (patch)
treed0d301930177438179ffb297f15c6555e1ed694d /include/sound
parent8303d769ea9e9626c4f0c3bd13e35e904a1253ab (diff)
ASoC: Consolidate enum and value enum controls
The implementations for enum and value enum controls are almost identical. The only difference is that the value enum uses an additional look-up table to map the control value to the register value, while the enum control uses a direct mapping. Enums and value enums can easily be distinguished at runtime, for value enums the values field of the snd_soc_enum struct contains the look-up table, while for enums it is NULL. This patch adds two new small helper functions called snd_soc_enum_item_to_val() and snd_soc_enum_val_to_item() which map between register value and control item. If the items field of the snd_soc_enum struct is NULL the function will do a direct mapping otherwise they'll use the look-up table to do the mapping. Using these small helper functions it is possible to use the same kcontrol handlers for both enums and value enums. The functions are added a inline functions in soc.h so they can also be used by the DAPM code to accomplish similar consolidation. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'include/sound')
-rw-r--r--include/sound/soc.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 49d6c10f4612..60c700ccc518 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -195,11 +195,7 @@
195 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \ 195 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
196 .private_value = (unsigned long)&xenum } 196 .private_value = (unsigned long)&xenum }
197#define SOC_VALUE_ENUM(xname, xenum) \ 197#define SOC_VALUE_ENUM(xname, xenum) \
198{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\ 198 SOC_ENUM(xname, xenum)
199 .info = snd_soc_info_enum_double, \
200 .get = snd_soc_get_value_enum_double, \
201 .put = snd_soc_put_value_enum_double, \
202 .private_value = (unsigned long)&xenum }
203#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\ 199#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
204 xhandler_get, xhandler_put) \ 200 xhandler_get, xhandler_put) \
205{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 201{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
@@ -510,10 +506,6 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
510 struct snd_ctl_elem_value *ucontrol); 506 struct snd_ctl_elem_value *ucontrol);
511int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 507int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
512 struct snd_ctl_elem_value *ucontrol); 508 struct snd_ctl_elem_value *ucontrol);
513int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
514 struct snd_ctl_elem_value *ucontrol);
515int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol);
517int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 509int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
518 struct snd_ctl_elem_info *uinfo); 510 struct snd_ctl_elem_info *uinfo);
519#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info 511#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
@@ -1182,6 +1174,30 @@ static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
1182 return 1; 1174 return 1;
1183} 1175}
1184 1176
1177static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
1178 unsigned int val)
1179{
1180 unsigned int i;
1181
1182 if (!e->values)
1183 return val;
1184
1185 for (i = 0; i < e->items; i++)
1186 if (val == e->values[i])
1187 return i;
1188
1189 return 0;
1190}
1191
1192static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
1193 unsigned int item)
1194{
1195 if (!e->values)
1196 return item;
1197
1198 return e->values[item];
1199}
1200
1185int snd_soc_util_init(void); 1201int snd_soc_util_init(void);
1186void snd_soc_util_exit(void); 1202void snd_soc_util_exit(void);
1187 1203