From: <gregkh@linuxfoundation.org>
To: stefan.bruens@rwth-aachen.de, Jonathan.Cameron@huawei.com,
alexander.levin@microsoft.com, gregkh@linuxfoundation.org
Cc: <stable@vger.kernel.org>, <stable-commits@vger.kernel.org>
Subject: Patch "iio: adc: ina2xx: Shift bus voltage register to mask flag bits" has been added to the 4.15-stable tree
Date: Fri, 16 Mar 2018 15:15:20 +0100 [thread overview]
Message-ID: <1521209720104155@kroah.com> (raw)
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.15-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.15 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.
>From foo@baz Fri Mar 16 15:11:07 CET 2018
From: "Stefan Br�ns" <stefan.bruens@rwth-aachen.de>
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" <stefan.bruens@rwth-aachen.de>
[ 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.
Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/iio/adc/ina2xx-adc.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -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_de
else
*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_de
return 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 stefan.bruens@rwth-aachen.de are
queue-4.15/iio-adc-ina2xx-shift-bus-voltage-register-to-mask-flag-bits.patch
reply other threads:[~2018-03-16 14:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1521209720104155@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=alexander.levin@microsoft.com \
--cc=stable-commits@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stefan.bruens@rwth-aachen.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).