aboutsummaryrefslogtreecommitdiffstats
path: root/sound
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
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')
-rw-r--r--sound/soc/codecs/twl4030.c8
-rw-r--r--sound/soc/soc-core.c16
-rw-r--r--sound/soc/soc-dapm.c22
3 files changed, 17 insertions, 29 deletions
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 391fcfc7b63b..2548f5c56885 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -999,7 +999,7 @@ static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
999 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 999 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1000 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 1000 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1001 unsigned short val; 1001 unsigned short val;
1002 unsigned short mask, bitmask; 1002 unsigned short mask;
1003 1003
1004 if (twl4030->configured) { 1004 if (twl4030->configured) {
1005 dev_err(codec->dev, 1005 dev_err(codec->dev,
@@ -1007,18 +1007,16 @@ static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
1007 return -EBUSY; 1007 return -EBUSY;
1008 } 1008 }
1009 1009
1010 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1011 ;
1012 if (ucontrol->value.enumerated.item[0] > e->max - 1) 1010 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1013 return -EINVAL; 1011 return -EINVAL;
1014 1012
1015 val = ucontrol->value.enumerated.item[0] << e->shift_l; 1013 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1016 mask = (bitmask - 1) << e->shift_l; 1014 mask = e->mask << e->shift_l;
1017 if (e->shift_l != e->shift_r) { 1015 if (e->shift_l != e->shift_r) {
1018 if (ucontrol->value.enumerated.item[1] > e->max - 1) 1016 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1019 return -EINVAL; 1017 return -EINVAL;
1020 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 1018 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1021 mask |= (bitmask - 1) << e->shift_r; 1019 mask |= e->mask << e->shift_r;
1022 } 1020 }
1023 1021
1024 return snd_soc_update_bits(codec, e->reg, mask, val); 1022 return snd_soc_update_bits(codec, e->reg, mask, val);
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);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index f7999e949acb..a18d115bc507 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -355,12 +355,10 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
355 case snd_soc_dapm_mux: { 355 case snd_soc_dapm_mux: {
356 struct soc_enum *e = (struct soc_enum *) 356 struct soc_enum *e = (struct soc_enum *)
357 w->kcontrol_news[i].private_value; 357 w->kcontrol_news[i].private_value;
358 int val, item, bitmask; 358 int val, item;
359 359
360 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
361 ;
362 val = soc_widget_read(w, e->reg); 360 val = soc_widget_read(w, e->reg);
363 item = (val >> e->shift_l) & (bitmask - 1); 361 item = (val >> e->shift_l) & e->mask;
364 362
365 p->connect = 0; 363 p->connect = 0;
366 for (i = 0; i < e->max; i++) { 364 for (i = 0; i < e->max; i++) {
@@ -2677,15 +2675,13 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2677 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 2675 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2678 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 2676 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2679 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2677 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2680 unsigned int val, bitmask; 2678 unsigned int val;
2681 2679
2682 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2683 ;
2684 val = snd_soc_read(widget->codec, e->reg); 2680 val = snd_soc_read(widget->codec, e->reg);
2685 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); 2681 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask;
2686 if (e->shift_l != e->shift_r) 2682 if (e->shift_l != e->shift_r)
2687 ucontrol->value.enumerated.item[1] = 2683 ucontrol->value.enumerated.item[1] =
2688 (val >> e->shift_r) & (bitmask - 1); 2684 (val >> e->shift_r) & e->mask;
2689 2685
2690 return 0; 2686 return 0;
2691} 2687}
@@ -2709,22 +2705,20 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2709 struct snd_soc_card *card = codec->card; 2705 struct snd_soc_card *card = codec->card;
2710 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2706 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2711 unsigned int val, mux, change; 2707 unsigned int val, mux, change;
2712 unsigned int mask, bitmask; 2708 unsigned int mask;
2713 struct snd_soc_dapm_update update; 2709 struct snd_soc_dapm_update update;
2714 int wi; 2710 int wi;
2715 2711
2716 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2717 ;
2718 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2712 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2719 return -EINVAL; 2713 return -EINVAL;
2720 mux = ucontrol->value.enumerated.item[0]; 2714 mux = ucontrol->value.enumerated.item[0];
2721 val = mux << e->shift_l; 2715 val = mux << e->shift_l;
2722 mask = (bitmask - 1) << e->shift_l; 2716 mask = e->mask << e->shift_l;
2723 if (e->shift_l != e->shift_r) { 2717 if (e->shift_l != e->shift_r) {
2724 if (ucontrol->value.enumerated.item[1] > e->max - 1) 2718 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2725 return -EINVAL; 2719 return -EINVAL;
2726 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2720 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2727 mask |= (bitmask - 1) << e->shift_r; 2721 mask |= e->mask << e->shift_r;
2728 } 2722 }
2729 2723
2730 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 2724 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);