diff options
author | Xin Xie <xxie@nvidia.com> | 2013-06-03 18:27:55 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2013-09-14 13:43:42 -0700 |
commit | 01a51b1b518f9bd868d881efb7ab3446be3fdee9 (patch) | |
tree | c79514f831b0b21a244cc01114cd2a67c6ede51a /drivers/hwmon | |
parent | 420505b4cfdd2ba08921048cd297c7239f41c5fe (diff) |
hwmon: ina230: fix negative current reading
bug 1298931
Change-Id: If0037afb285b88dde11fe5f40def8f8fe9727c56
Signed-off-by: Xin Xie <xxie@nvidia.com>
Reviewed-on: http://git-master/r/235215
(cherry picked from commit 339d494c5790e7a96d00e94e7e6c68716644c18a)
Reviewed-on: http://git-master/r/266525
Reviewed-by: Timo Alho <talho@nvidia.com>
GVS: Gerrit_Virtual_Submit
Tested-by: Timo Alho <talho@nvidia.com>
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/ina230.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/hwmon/ina230.c b/drivers/hwmon/ina230.c index 92e2d3c927f2..5766938996ea 100644 --- a/drivers/hwmon/ina230.c +++ b/drivers/hwmon/ina230.c @@ -458,21 +458,22 @@ static s32 show_current(struct device *dev, } /* getting current readings in milli amps*/ - current_mA = be16_to_cpu(i2c_smbus_read_word_data(client, - INA230_CURRENT)); - if (current_mA < 0) { + retval = i2c_smbus_read_word_data(client, INA230_CURRENT); + if (retval < 0) { mutex_unlock(&data->mutex); - return -EINVAL; + return retval; } + current_mA = (s16) be16_to_cpu(retval); ensure_enabled_end(client); mutex_unlock(&data->mutex); if (data->pdata->shunt_polarity_inverted) - current_mA = (s16)current_mA * -1; + current_mA *= -1; - current_mA = - (current_mA * data->pdata->power_lsb) / data->pdata->divisor; + current_mA *= (s16) data->pdata->power_lsb; + if (data->pdata->divisor) + current_mA /= (s16) data->pdata->divisor; if (data->pdata->precision_multiplier) current_mA /= (s16) data->pdata->precision_multiplier; |