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>
This commit is contained in:
Philip Chen
2017-08-16 13:58:29 -07:00
committed by chrome-bot
parent 104fa97f67
commit 20f05a3488

View File

@@ -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;