From 20f05a34887345dc512c3d9aed8deb485018bb7c Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Wed, 16 Aug 2017 13:58:29 -0700 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/617654 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Shawn N --- driver/battery/max17055.c | 4 ++-- 1 file 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, ®)) 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, ®) && fake_state_of_charge < 0) @@ -254,7 +254,7 @@ void battery_get_params(struct batt_params *batt) if (max17055_read(REG_AVERAGE_CURRENT, ®)) 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;