ASoC: Avoid recalculating the bitmask for SOC_ENUM controls
For ENUM controls the bitmask is calculated based on the number of items. Currently this is done each time the control is accessed. And while the performance impact of this should be negligible we can easily do better. The roundup_pow_of_two macro performs the same calculation which is currently done manually, but it is also possible to use this macro with compile time constants and so it can be used to initialize static data. So we can use it to initialize the mask field of a ENUM control during its declaration. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Este commit está contenido en:

cometido por
Mark Brown

padre
4c2474c007
commit
86767b7d5b
@@ -2413,16 +2413,14 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
|
||||
{
|
||||
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
||||
unsigned int val, bitmask;
|
||||
unsigned int val;
|
||||
|
||||
for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
|
||||
;
|
||||
val = snd_soc_read(codec, e->reg);
|
||||
ucontrol->value.enumerated.item[0]
|
||||
= (val >> e->shift_l) & (bitmask - 1);
|
||||
= (val >> e->shift_l) & e->mask;
|
||||
if (e->shift_l != e->shift_r)
|
||||
ucontrol->value.enumerated.item[1] =
|
||||
(val >> e->shift_r) & (bitmask - 1);
|
||||
(val >> e->shift_r) & e->mask;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2443,19 +2441,17 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
|
||||
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
||||
unsigned int val;
|
||||
unsigned int mask, bitmask;
|
||||
unsigned int mask;
|
||||
|
||||
for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
|
||||
;
|
||||
if (ucontrol->value.enumerated.item[0] > e->max - 1)
|
||||
return -EINVAL;
|
||||
val = ucontrol->value.enumerated.item[0] << e->shift_l;
|
||||
mask = (bitmask - 1) << e->shift_l;
|
||||
mask = e->mask << e->shift_l;
|
||||
if (e->shift_l != e->shift_r) {
|
||||
if (ucontrol->value.enumerated.item[1] > e->max - 1)
|
||||
return -EINVAL;
|
||||
val |= ucontrol->value.enumerated.item[1] << e->shift_r;
|
||||
mask |= (bitmask - 1) << e->shift_r;
|
||||
mask |= e->mask << e->shift_r;
|
||||
}
|
||||
|
||||
return snd_soc_update_bits_locked(codec, e->reg, mask, val);
|
||||
|
Referencia en una nueva incidencia
Block a user