aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-09-14 07:57:27 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-09-18 22:51:23 -0400
commit86767b7d5b3cdbd105e7d7066d671b52aa208188 (patch)
treefec3b10d199fab827a8fdf66857e2b6131649a7d /sound/soc/soc-core.c
parent4c2474c007867c102c96482f3bacb1fdf209958c (diff)
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>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index e5b0713e6f3c..9a6daf997319 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2413,16 +2413,14 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2413{ 2413{
2414 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2414 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2415 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2415 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2416 unsigned int val, bitmask; 2416 unsigned int val;
2417 2417
2418 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2419 ;
2420 val = snd_soc_read(codec, e->reg); 2418 val = snd_soc_read(codec, e->reg);
2421 ucontrol->value.enumerated.item[0] 2419 ucontrol->value.enumerated.item[0]
2422 = (val >> e->shift_l) & (bitmask - 1); 2420 = (val >> e->shift_l) & e->mask;
2423 if (e->shift_l != e->shift_r) 2421 if (e->shift_l != e->shift_r)
2424 ucontrol->value.enumerated.item[1] = 2422 ucontrol->value.enumerated.item[1] =
2425 (val >> e->shift_r) & (bitmask - 1); 2423 (val >> e->shift_r) & e->mask;
2426 2424
2427 return 0; 2425 return 0;
2428} 2426}
@@ -2443,19 +2441,17 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2443 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2441 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2444 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2442 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2445 unsigned int val; 2443 unsigned int val;
2446 unsigned int mask, bitmask; 2444 unsigned int mask;
2447 2445
2448 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2449 ;
2450 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2446 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2451 return -EINVAL; 2447 return -EINVAL;
2452 val = ucontrol->value.enumerated.item[0] << e->shift_l; 2448 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2453 mask = (bitmask - 1) << e->shift_l; 2449 mask = e->mask << e->shift_l;
2454 if (e->shift_l != e->shift_r) { 2450 if (e->shift_l != e->shift_r) {
2455 if (ucontrol->value.enumerated.item[1] > e->max - 1) 2451 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2456 return -EINVAL; 2452 return -EINVAL;
2457 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2453 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2458 mask |= (bitmask - 1) << e->shift_r; 2454 mask |= e->mask << e->shift_r;
2459 } 2455 }
2460 2456
2461 return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2457 return snd_soc_update_bits_locked(codec, e->reg, mask, val);