summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2017-08-16 13:58:29 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-08-18 14:27:19 -0700
commit20f05a34887345dc512c3d9aed8deb485018bb7c (patch)
tree1e60ddc8f8f45401245257bf57f3d59562b31fe8 /driver
parent104fa97f671c84d27f162bc25a6d2e68f1ffff6c (diff)
downloadchrome-ec-20f05a34887345dc512c3d9aed8deb485018bb7c.tar.gz
battery/max17055: Process negative current/temperature right
On max17055, current/temperature register values are in 2's complement format. Therefore we need to consider the case of negative values before doing bitwise operation. BUG=b:63870414 BRANCH=none TEST=run 'battery' command and confirm the reported discharge current looks reasonable. Change-Id: Iea0c554aecf2b410fc27b547e01ee7a583a0dd00 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/617654 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/battery/max17055.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c
index f5c3e52400..c676ce22a5 100644
--- a/driver/battery/max17055.c
+++ b/driver/battery/max17055.c
@@ -237,7 +237,7 @@ void battery_get_params(struct batt_params *batt)
if (max17055_read(REG_TEMPERATURE, &reg))
batt->flags |= BATT_FLAG_BAD_TEMPERATURE;
- batt->temperature = TEMPERATURE_CONV(reg);
+ batt->temperature = TEMPERATURE_CONV((int16_t)reg);
if (max17055_read(REG_STATE_OF_CHARGE, &reg) &&
fake_state_of_charge < 0)
@@ -254,7 +254,7 @@ void battery_get_params(struct batt_params *batt)
if (max17055_read(REG_AVERAGE_CURRENT, &reg))
batt->flags |= BATT_FLAG_BAD_CURRENT;
- batt->current = CURRENT_CONV(reg);
+ batt->current = CURRENT_CONV((int16_t)reg);
/* Default to not desiring voltage and current */
batt->desired_voltage = batt->desired_current = 0;