hwmon: (ina209) Handled signed registers
authorJoe Schaack <jschaack@xes-inc.com>
Tue, 18 Apr 2017 12:15:50 +0000 (07:15 -0500)
committerGuenter Roeck <linux@roeck-us.net>
Fri, 21 Apr 2017 19:30:09 +0000 (12:30 -0700)
The shunt voltage and current registers are signed 16-bit values so
handle them as such.

Signed-off-by: Joe Schaack <jschaack@xes-inc.com>
Reviewed-by: Aaron Sierra <asierra@xes-inc.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/ina209.c

index c5f20f03e0be280228f7d578ac28ae94b04feb3e..aa0768ce8aeab54a0b3cc7988008d434df6eaa3c 100644 (file)
@@ -117,7 +117,7 @@ static long ina209_from_reg(const u8 reg, const u16 val)
        case INA209_SHUNT_VOLTAGE_POS_WARN:
        case INA209_SHUNT_VOLTAGE_NEG_WARN:
                /* LSB=10 uV. Convert to mV. */
-               return DIV_ROUND_CLOSEST(val, 100);
+               return DIV_ROUND_CLOSEST((s16)val, 100);
 
        case INA209_BUS_VOLTAGE:
        case INA209_BUS_VOLTAGE_MAX_PEAK:
@@ -146,7 +146,7 @@ static long ina209_from_reg(const u8 reg, const u16 val)
 
        case INA209_CURRENT:
                /* LSB=1 mA (selected). Is in mA */
-               return val;
+               return (s16)val;
        }
 
        /* programmer goofed */