Patch "iio: adc: ina2xx: Shift bus voltage register to mask flag bits" has been added to the 4.14-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
iio: adc: ina2xx: Shift bus voltage register to mask flag bits
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
iio-adc-ina2xx-shift-bus-voltage-register-to-mask-flag-bits.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Fri Mar 16 15:43:17 CET 2018
From: "Stefan Br�ns" <[email protected]>
Date: Sat, 28 Oct 2017 23:12:46 +0200
Subject: iio: adc: ina2xx: Shift bus voltage register to mask flag bits
From: "Stefan Br�ns" <[email protected]>
[ Upstream commit 2e64438487697f3f099946edc8acd4ceea6b1ab2 ]
Lower bits of the INA219/220 bus voltage register are conversion status flags, properly shift the value.
When reading via IIO buffer, the value is passed on unaltered, shifting is the responsibility of the user.
--- drivers/iio/adc/ina2xx-adc.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/iio/adc/ina2xx-adc.c +17 -9
@@ -44,7 +44,6 @@#define INA226_MASK_ENABLE 0x06#define INA226_CVRF BIT(3) -#define INA219_CNVR BIT(1)#define INA2XX_MAX_REGISTERS 8
@@ -79,6 +78,11 @@#define INA226_ITS_MASK GENMASK(5, 3)#define INA226_SHIFT_ITS (val) ((val) << 3) +/* INA219 Bus voltage register, low bits are flags */ +#define INA219_OVF BIT(0) +#define INA219_CNVR BIT(1) +#define INA219_BUS_VOLTAGE_SHIFT 3 +/* Cosmetic macro giving the sampling period for a full P=UxI cycle */ #define SAMPLING_PERIOD (c) ((c->int_time_vbus + c->int_time_vshunt) \ * c->avg)
@@ -112,7 +116,7 @@ struct ina2xx_config {u16 config_default;int calibration_factor;int shunt_div; -int bus_voltage_shift; +int bus_voltage_shift;/* position of lsb */ int bus_voltage_lsb;/* uV */ int power_lsb;/* uW */ enum ina2xx_ids chip_id;
@@ -135,7 +139,7 @@ static const struct ina2xx_config ina2xx .config_default = INA219_CONFIG_DEFAULT, .calibration_factor = 40960000, .shunt_div = 100, - .bus_voltage_shift = 3, + .bus_voltage_shift = INA219_BUS_VOLTAGE_SHIFT, .bus_voltage_lsb = 4000, .power_lsb = 20000, .chip_id = ina219,
@@ -170,6 +174,9 @@ static int ina2xx_read_raw(struct iio_deelse *val = regval; +if (chan->address ==INA2XX_BUS_VOLTAGE ) + *val >>= chip->config->bus_voltage_shift; +return IIO_VAL_INT ;case IIO_CHAN_INFO_OVERSAMPLING_RATIO :
@@ -203,9 +210,9 @@ static int ina2xx_read_raw(struct iio_dereturn IIO_VAL_FRACTIONAL ;case INA2XX_BUS_VOLTAGE : -/* processed (mV) = raw*lsb (uV) / (1000 << shift) */ +/* processed (mV) = raw * lsb (uV) / 1000 */ *val = chip->config->bus_voltage_lsb; - *val2 =1000 << chip->config->bus_voltage_shift; + *val2 =1000 ;return IIO_VAL_FRACTIONAL ;case INA2XX_POWER :
@@ -532,7 +539,7 @@ static ssize_t ina2xx_shunt_resistor_sto* Sampling Freq is a consequence of the integration times of * the Voltage channels. */ -#define INA219_CHAN_VOLTAGE (_index, _address) { \ +#define INA219_CHAN_VOLTAGE (_index, _address, _shift) { \ .type = IIO_VOLTAGE, \ .address = (_address), \ .indexed = 1, \
@@ -544,7 +551,8 @@ static ssize_t ina2xx_shunt_resistor_sto .scan_index = (_index), \ .scan_type = { \ .sign = 'u', \ - .realbits = 16, \ + .shift = _shift, \ + .realbits = 16 - _shift, \ .storagebits = 16, \ .endianness = IIO_LE, \ } \
@@ -579,8 +587,8 @@ static const struct iio_chan_spec ina226 };static const struct iio_chan_spec ina219_channels[] = { -INA219_CHAN_VOLTAGE (0 ,INA2XX_SHUNT_VOLTAGE ), -INA219_CHAN_VOLTAGE (1 ,INA2XX_BUS_VOLTAGE ), +INA219_CHAN_VOLTAGE (0 ,INA2XX_SHUNT_VOLTAGE ,0 ), +INA219_CHAN_VOLTAGE (1 ,INA2XX_BUS_VOLTAGE ,INA219_BUS_VOLTAGE_SHIFT ),INA219_CHAN (IIO_POWER ,2 ,INA2XX_POWER ),INA219_CHAN (IIO_CURRENT ,3 ,INA2XX_CURRENT ),IIO_CHAN_SOFT_TIMESTAMP (4 ),
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/iio-adc-ina2xx-shift-bus-voltage-register-to-mask-flag-bits.patch