Commit 6c6bc851 authored by Jonathan Cameron's avatar Jonathan Cameron

staging:iio:adc:ad7280a: Remove shift from cb_mask state cache.

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: default avatarMarcelo Schmitt <marcelo.schmitt1@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarMarcelo Schmitt <marcelo.schmitt1@gmail.com>
Link: https://lore.kernel.org/r/20220206190328.333093-19-jic23@kernel.org
parent bc6fbf11
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
#define AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN (BIT(7) | BIT(6)) #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_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_CB1_TIMER_REG 0x15 /* D7 to D0, Read/write */
#define AD7280A_CB_TIMER_VAL_MSK GENMASK(7, 3) #define AD7280A_CB_TIMER_VAL_MSK GENMASK(7, 3)
#define AD7280A_CB2_TIMER_REG 0x16 /* D7 to D0, Read/write */ #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, ...@@ -474,7 +475,7 @@ static ssize_t ad7280_show_balance_sw(struct iio_dev *indio_dev,
return sysfs_emit(buf, "%d\n", return sysfs_emit(buf, "%d\n",
!!(st->cb_mask[chan->address >> 8] & !!(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, 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, ...@@ -496,12 +497,13 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev,
mutex_lock(&st->lock); mutex_lock(&st->lock);
if (readin) if (readin)
st->cb_mask[devaddr] |= 1 << (ch + 2); st->cb_mask[devaddr] |= BIT(ch);
else else
st->cb_mask[devaddr] &= ~(1 << (ch + 2)); st->cb_mask[devaddr] &= ~BIT(ch);
ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE_REG, ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE_REG, 0,
0, st->cb_mask[devaddr]); FIELD_PREP(AD7280A_CELL_BALANCE_CHAN_BITMAP_MSK,
st->cb_mask[devaddr]));
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
return ret ? ret : len; return ret ? ret : len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment