From ccea4b67f2e36a505ddf546bde284f75d728add0 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Tue, 13 Mar 2018 12:38:44 -0700 Subject: battery/max17055: Fix the unit of cycle count The cycle counts we get from battery_cycle_count() is in the unit of 1%. But we should convert it to absolute count to match the behavior of a smart battery. BUG=b:74576000 BRANCH=scarlet TEST='ectool battery' shows reasonable cycle counts Change-Id: I9d351f8766c90e0addb72a088917ddadfa6c840a Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/961303 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Philip Chen Reviewed-by: Aseda Aboagye --- driver/battery/max17055.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'driver/battery/max17055.c') diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c index 4836cf242d..9be2a14651 100644 --- a/driver/battery/max17055.c +++ b/driver/battery/max17055.c @@ -34,6 +34,8 @@ #define TEMPERATURE_CONV(REG) (((REG * 10) >> 8) + 2731) /* Percentage reg value to 1% */ #define PERCENTAGE_CONV(REG) (REG >> 8) +/* Cycle count reg value (LSB = 1%) to absolute count (100%) */ +#define CYCLE_COUNT_CONV(REG) ((REG * 5) >> 9) /* Useful macros */ #define MAX17055_READ_DEBUG(offset, ptr_reg) \ @@ -135,7 +137,13 @@ int battery_time_to_full(int *minutes) int battery_cycle_count(int *count) { - return max17055_read(REG_CYCLE_COUNT, count); + int rv; + int reg; + + rv = max17055_read(REG_CYCLE_COUNT, ®); + if (!rv) + *count = CYCLE_COUNT_CONV(reg); + return rv; } int battery_design_capacity(int *capacity) -- cgit v1.2.1