Commit 32f228cb authored by Jeremy Fertic's avatar Jeremy Fertic Committed by Jonathan Cameron

staging: iio: adt7316: change interpretation of write to dac update mode

Based on the output of adt7316_show_all_DAC_update_modes() and
adt7316_show_DAC_update_mode(), adt7316_store_DAC_update_mode() should
expect the user to enter an integer input from 0 to 3. The user input is
currently expected to account for the actual bit positions in the register.
For example, choosing option 3 would require a write of 0x30 (actually 48
since it expects base 10). To address this inconsistency, create a shift
macro to be used in the valid input check as well as the calculation for
the register write.
Signed-off-by: default avatarJeremy Fertic <jeremyfertic@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 9f287a1c
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
*/ */
#define ADT7316_DA_2VREF_CH_MASK 0xF #define ADT7316_DA_2VREF_CH_MASK 0xF
#define ADT7316_DA_EN_MODE_MASK 0x30 #define ADT7316_DA_EN_MODE_MASK 0x30
#define ADT7316_DA_EN_MODE_SHIFT 4
#define ADT7316_DA_EN_MODE_SINGLE 0x00 #define ADT7316_DA_EN_MODE_SINGLE 0x00
#define ADT7316_DA_EN_MODE_AB_CD 0x10 #define ADT7316_DA_EN_MODE_AB_CD 0x10
#define ADT7316_DA_EN_MODE_ABCD 0x20 #define ADT7316_DA_EN_MODE_ABCD 0x20
...@@ -884,11 +885,11 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev, ...@@ -884,11 +885,11 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev,
return -EPERM; return -EPERM;
ret = kstrtou8(buf, 10, &data); ret = kstrtou8(buf, 10, &data);
if (ret || data > ADT7316_DA_EN_MODE_MASK) if (ret || data > (ADT7316_DA_EN_MODE_MASK >> ADT7316_DA_EN_MODE_SHIFT))
return -EINVAL; return -EINVAL;
dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK); dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK);
dac_config |= data; dac_config |= data << ADT7316_DA_EN_MODE_SHIFT;
ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config); ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
if (ret) if (ret)
......
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