From a22e9ee8257a1b9c1820af52be406ba0d158a2af Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 26 Aug 2013 19:17:33 +0530 Subject: hwmon: ina230: fix negative power readings - show_power2 api calculates power using shunt voltage - if shunt voltage is negative, power and current readings are also calculated negative - fix this by taking absolute value of shunt voltage Bug 1353426 Change-Id: I10deb33a0297af52da88385b105edd9bc2649d94 Signed-off-by: Deepak Nibade Reviewed-on: http://git-master/r/266129 (cherry picked from commit bdfa16243edcac9b07bbbe7133374494f4ef3b6f) Reviewed-on: http://git-master/r/273608 GVS: Gerrit_Virtual_Submit Reviewed-by: Sachin Nikam --- drivers/hwmon/ina230.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/hwmon') diff --git a/drivers/hwmon/ina230.c b/drivers/hwmon/ina230.c index 5766938996ea..b4788135ef03 100644 --- a/drivers/hwmon/ina230.c +++ b/drivers/hwmon/ina230.c @@ -505,6 +505,7 @@ static s32 show_current2(struct device *dev, mutex_unlock(&data->mutex); voltage_uV = shuntv_register_to_uv(voltage_uV); + voltage_uV = abs(voltage_uV); inverse_shunt_resistor = 1000 / data->pdata->resistor; current_mA = voltage_uV * inverse_shunt_resistor / 1000; @@ -594,6 +595,7 @@ static s32 show_power2(struct device *dev, voltage_mV = busv_register_to_mv(voltage_mV); voltage_uV = shuntv_register_to_uv(voltage_uV); + voltage_uV = abs(voltage_uV); inverse_shunt_resistor = 1000 / data->pdata->resistor; current_mA = voltage_uV * inverse_shunt_resistor / 1000; -- cgit v1.2.3