From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> Making the local storage of the Cell Balance mask a simple bitmap and then shifting it only at time of register write simplifies several code paths. Suggested-by: Marcelo Schmitt <marcelo.schmitt1@xxxxxxxxx> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> --- drivers/staging/iio/adc/ad7280a.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index a32c32a1226a..a7e16144b013 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -88,6 +88,7 @@ #define AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN (BIT(7) | BIT(6)) #define AD7280A_CELL_BALANCE_REG 0x14 /* D7 to D0, Read/write */ +#define AD7280A_CELL_BALANCE_CHAN_BITMAP_MSK GENMASK(7, 2) #define AD7280A_CB1_TIMER_REG 0x15 /* D7 to D0, Read/write */ #define AD7280A_CB_TIMER_VAL_MSK GENMASK(7, 3) #define AD7280A_CB2_TIMER_REG 0x16 /* D7 to D0, Read/write */ @@ -474,7 +475,7 @@ static ssize_t ad7280_show_balance_sw(struct iio_dev *indio_dev, return sysfs_emit(buf, "%d\n", !!(st->cb_mask[chan->address >> 8] & - (1 << ((chan->address & 0xFF) + 2)))); + BIT(chan->address & 0xFF))); } static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev, @@ -496,12 +497,13 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev, mutex_lock(&st->lock); if (readin) - st->cb_mask[devaddr] |= 1 << (ch + 2); + st->cb_mask[devaddr] |= BIT(ch); else - st->cb_mask[devaddr] &= ~(1 << (ch + 2)); + st->cb_mask[devaddr] &= ~BIT(ch); - ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE_REG, - 0, st->cb_mask[devaddr]); + ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE_REG, 0, + FIELD_PREP(AD7280A_CELL_BALANCE_CHAN_BITMAP_MSK, + st->cb_mask[devaddr])); mutex_unlock(&st->lock); return ret ? ret : len; -- 2.35.1