* [PATCH v2] hwmon: (ina2xx) Cast to s16 on shunt and current regs
@ 2014-06-08 21:06 ` Fabio Baltieri
0 siblings, 0 replies; 4+ messages in thread
From: Fabio Baltieri @ 2014-06-08 21:06 UTC (permalink / raw)
To: Guenter Roeck, Jean Delvare; +Cc: lm-sensors, linux-kernel, Fabio Baltieri
All devices supported by ina2xx are bidirectional and reports the
measured shunt voltage and power values as a signed 16 bit, but the
current driver implementation caches all registers as u16, leading to an
incorrect sign extension when reporting to the userspace in
ina2xx_get_value().
This patch fixes the problem by casting the signed registers to s16.
Tested on an INA219.
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
drivers/hwmon/ina2xx.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 93d26e8..bfd3f3e 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -148,7 +148,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
switch (reg) {
case INA2XX_SHUNT_VOLTAGE:
- val = DIV_ROUND_CLOSEST(data->regs[reg],
+ /* signed register */
+ val = DIV_ROUND_CLOSEST((s16)data->regs[reg],
data->config->shunt_div);
break;
case INA2XX_BUS_VOLTAGE:
@@ -160,8 +161,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
val = data->regs[reg] * data->config->power_lsb;
break;
case INA2XX_CURRENT:
- /* LSB=1mA (selected). Is in mA */
- val = data->regs[reg];
+ /* signed register, LSB=1mA (selected), in mA */
+ val = (s16)data->regs[reg];
break;
default:
/* programmer goofed */
--
1.8.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [lm-sensors] [PATCH v2] hwmon: (ina2xx) Cast to s16 on shunt and current regs
@ 2014-06-08 21:06 ` Fabio Baltieri
0 siblings, 0 replies; 4+ messages in thread
From: Fabio Baltieri @ 2014-06-08 21:06 UTC (permalink / raw)
To: Guenter Roeck, Jean Delvare; +Cc: lm-sensors, linux-kernel, Fabio Baltieri
All devices supported by ina2xx are bidirectional and reports the
measured shunt voltage and power values as a signed 16 bit, but the
current driver implementation caches all registers as u16, leading to an
incorrect sign extension when reporting to the userspace in
ina2xx_get_value().
This patch fixes the problem by casting the signed registers to s16.
Tested on an INA219.
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
---
drivers/hwmon/ina2xx.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 93d26e8..bfd3f3e 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -148,7 +148,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
switch (reg) {
case INA2XX_SHUNT_VOLTAGE:
- val = DIV_ROUND_CLOSEST(data->regs[reg],
+ /* signed register */
+ val = DIV_ROUND_CLOSEST((s16)data->regs[reg],
data->config->shunt_div);
break;
case INA2XX_BUS_VOLTAGE:
@@ -160,8 +161,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
val = data->regs[reg] * data->config->power_lsb;
break;
case INA2XX_CURRENT:
- /* LSB=1mA (selected). Is in mA */
- val = data->regs[reg];
+ /* signed register, LSB=1mA (selected), in mA */
+ val = (s16)data->regs[reg];
break;
default:
/* programmer goofed */
--
1.8.4
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] hwmon: (ina2xx) Cast to s16 on shunt and current regs
2014-06-08 21:06 ` [lm-sensors] " Fabio Baltieri
@ 2014-06-09 14:45 ` Guenter Roeck
-1 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2014-06-09 14:45 UTC (permalink / raw)
To: Fabio Baltieri, Jean Delvare; +Cc: lm-sensors, linux-kernel
On 06/08/2014 02:06 PM, Fabio Baltieri wrote:
> All devices supported by ina2xx are bidirectional and reports the
> measured shunt voltage and power values as a signed 16 bit, but the
> current driver implementation caches all registers as u16, leading to an
> incorrect sign extension when reporting to the userspace in
> ina2xx_get_value().
>
> This patch fixes the problem by casting the signed registers to s16.
> Tested on an INA219.
>
> Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [lm-sensors] [PATCH v2] hwmon: (ina2xx) Cast to s16 on shunt and current regs
@ 2014-06-09 14:45 ` Guenter Roeck
0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2014-06-09 14:45 UTC (permalink / raw)
To: Fabio Baltieri, Jean Delvare; +Cc: lm-sensors, linux-kernel
On 06/08/2014 02:06 PM, Fabio Baltieri wrote:
> All devices supported by ina2xx are bidirectional and reports the
> measured shunt voltage and power values as a signed 16 bit, but the
> current driver implementation caches all registers as u16, leading to an
> incorrect sign extension when reporting to the userspace in
> ina2xx_get_value().
>
> This patch fixes the problem by casting the signed registers to s16.
> Tested on an INA219.
>
> Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Applied.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-06-09 14:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-08 21:06 [PATCH v2] hwmon: (ina2xx) Cast to s16 on shunt and current regs Fabio Baltieri
2014-06-08 21:06 ` [lm-sensors] " Fabio Baltieri
2014-06-09 14:45 ` Guenter Roeck
2014-06-09 14:45 ` [lm-sensors] " Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.