@@ -7,6 +7,7 @@
* Copyright (c) 2012 Ondrej Zary <linux@rainbow-software.org>
*/
+#include <linux/bitfield.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/control.h>
@@ -212,11 +213,10 @@ static int snd_wm8766_ctl_get(struct snd_kcontrol *kcontrol,
if (wm->ctl[n].get)
wm->ctl[n].get(wm, &val1, &val2);
else {
- val1 = wm->regs[wm->ctl[n].reg1] & wm->ctl[n].mask1;
- val1 >>= __ffs(wm->ctl[n].mask1);
+ val1 = field_get(wm->ctl[n].mask1, wm->regs[wm->ctl[n].reg1]);
if (wm->ctl[n].flags & WM8766_FLAG_STEREO) {
- val2 = wm->regs[wm->ctl[n].reg2] & wm->ctl[n].mask2;
- val2 >>= __ffs(wm->ctl[n].mask2);
+ val2 = field_get(wm->ctl[n].mask2,
+ wm->regs[wm->ctl[n].reg2]);
if (wm->ctl[n].flags & WM8766_FLAG_VOL_UPDATE)
val2 &= ~WM8766_VOL_UPDATE;
}
@@ -251,19 +251,19 @@ static int snd_wm8766_ctl_put(struct snd_kcontrol *kcontrol,
wm->ctl[n].set(wm, regval1, regval2);
else {
val = wm->regs[wm->ctl[n].reg1] & ~wm->ctl[n].mask1;
- val |= regval1 << __ffs(wm->ctl[n].mask1);
+ val |= field_prep(wm->ctl[n].mask1, regval1);
/* both stereo controls in one register */
if (wm->ctl[n].flags & WM8766_FLAG_STEREO &&
wm->ctl[n].reg1 == wm->ctl[n].reg2) {
val &= ~wm->ctl[n].mask2;
- val |= regval2 << __ffs(wm->ctl[n].mask2);
+ val |= field_prep(wm->ctl[n].mask2, regval2);
}
snd_wm8766_write(wm, wm->ctl[n].reg1, val);
/* stereo controls in different registers */
if (wm->ctl[n].flags & WM8766_FLAG_STEREO &&
wm->ctl[n].reg1 != wm->ctl[n].reg2) {
val = wm->regs[wm->ctl[n].reg2] & ~wm->ctl[n].mask2;
- val |= regval2 << __ffs(wm->ctl[n].mask2);
+ val |= field_prep(wm->ctl[n].mask2, regval2);
if (wm->ctl[n].flags & WM8766_FLAG_VOL_UPDATE)
val |= WM8766_VOL_UPDATE;
snd_wm8766_write(wm, wm->ctl[n].reg2, val);
@@ -7,6 +7,7 @@
* Copyright (c) 2012 Ondrej Zary <linux@rainbow-software.org>
*/
+#include <linux/bitfield.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/control.h>
@@ -486,11 +487,10 @@ static int snd_wm8776_ctl_get(struct snd_kcontrol *kcontrol,
if (wm->ctl[n].get)
wm->ctl[n].get(wm, &val1, &val2);
else {
- val1 = wm->regs[wm->ctl[n].reg1] & wm->ctl[n].mask1;
- val1 >>= __ffs(wm->ctl[n].mask1);
+ val1 = field_get(wm->ctl[n].mask1, wm->regs[wm->ctl[n].reg1]);
if (wm->ctl[n].flags & WM8776_FLAG_STEREO) {
- val2 = wm->regs[wm->ctl[n].reg2] & wm->ctl[n].mask2;
- val2 >>= __ffs(wm->ctl[n].mask2);
+ val2 = field_get(wm->ctl[n].mask2,
+ wm->regs[wm->ctl[n].reg2]);
if (wm->ctl[n].flags & WM8776_FLAG_VOL_UPDATE)
val2 &= ~WM8776_VOL_UPDATE;
}
@@ -525,19 +525,19 @@ static int snd_wm8776_ctl_put(struct snd_kcontrol *kcontrol,
wm->ctl[n].set(wm, regval1, regval2);
else {
val = wm->regs[wm->ctl[n].reg1] & ~wm->ctl[n].mask1;
- val |= regval1 << __ffs(wm->ctl[n].mask1);
+ val |= field_prep(wm->ctl[n].mask1, regval1);
/* both stereo controls in one register */
if (wm->ctl[n].flags & WM8776_FLAG_STEREO &&
wm->ctl[n].reg1 == wm->ctl[n].reg2) {
val &= ~wm->ctl[n].mask2;
- val |= regval2 << __ffs(wm->ctl[n].mask2);
+ val |= field_prep(wm->ctl[n].mask2, regval2);
}
snd_wm8776_write(wm, wm->ctl[n].reg1, val);
/* stereo controls in different registers */
if (wm->ctl[n].flags & WM8776_FLAG_STEREO &&
wm->ctl[n].reg1 != wm->ctl[n].reg2) {
val = wm->regs[wm->ctl[n].reg2] & ~wm->ctl[n].mask2;
- val |= regval2 << __ffs(wm->ctl[n].mask2);
+ val |= field_prep(wm->ctl[n].mask2, regval2);
if (wm->ctl[n].flags & WM8776_FLAG_VOL_UPDATE)
val |= WM8776_VOL_UPDATE;
snd_wm8776_write(wm, wm->ctl[n].reg2, val);
Use the field_{get,prep}() helpers, instead of open-coding the same operations. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> --- Compile-tested only. Marked RFC, as this depends on [PATCH 01/17], but follows a different path to upstream. --- sound/pci/ice1712/wm8766.c | 14 +++++++------- sound/pci/ice1712/wm8776.c | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-)