Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging:iio:ad7150: fix threshold mode config bit

According to the AD7150 configuration register description, bit 7 assumes
value 1 when the threshold mode is fixed and 0 when it is adaptive,
however, the operation that identifies this mode was considering the
opposite values.

This patch renames the boolean variable to describe it correctly and
properly replaces it in the places where it is used.

Fixes: 531efd6aa0991 ("staging:iio:adc:ad7150: chan_spec conv + i2c_smbus commands + drop unused poweroff timeout control.")
Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Melissa Wen and committed by
Jonathan Cameron
df4d737e e61ff0fb

+11 -8
+11 -8
drivers/staging/iio/cdc/ad7150.c
··· 5 5 * Copyright 2010-2011 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/interrupt.h> 9 10 #include <linux/device.h> 10 11 #include <linux/kernel.h> ··· 131 130 { 132 131 int ret; 133 132 u8 threshtype; 134 - bool adaptive; 133 + bool thrfixed; 135 134 struct ad7150_chip_info *chip = iio_priv(indio_dev); 136 135 137 136 ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); ··· 139 138 return ret; 140 139 141 140 threshtype = (ret >> 5) & 0x03; 142 - adaptive = !!(ret & 0x80); 141 + 142 + /*check if threshold mode is fixed or adaptive*/ 143 + thrfixed = FIELD_GET(AD7150_CFG_FIX, ret); 143 144 144 145 switch (type) { 145 146 case IIO_EV_TYPE_MAG_ADAPTIVE: 146 147 if (dir == IIO_EV_DIR_RISING) 147 - return adaptive && (threshtype == 0x1); 148 - return adaptive && (threshtype == 0x0); 148 + return !thrfixed && (threshtype == 0x1); 149 + return !thrfixed && (threshtype == 0x0); 149 150 case IIO_EV_TYPE_THRESH_ADAPTIVE: 150 151 if (dir == IIO_EV_DIR_RISING) 151 - return adaptive && (threshtype == 0x3); 152 - return adaptive && (threshtype == 0x2); 152 + return !thrfixed && (threshtype == 0x3); 153 + return !thrfixed && (threshtype == 0x2); 153 154 case IIO_EV_TYPE_THRESH: 154 155 if (dir == IIO_EV_DIR_RISING) 155 - return !adaptive && (threshtype == 0x1); 156 - return !adaptive && (threshtype == 0x0); 156 + return thrfixed && (threshtype == 0x1); 157 + return thrfixed && (threshtype == 0x0); 157 158 default: 158 159 break; 159 160 }