summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2018-03-13 12:38:44 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-03-14 04:07:09 -0700
commitccea4b67f2e36a505ddf546bde284f75d728add0 (patch)
tree7ef350b4cff0613e6ef31e8d7474f5e9d3cbe8cd
parente325981c7d39f7160fafd4681384e410a137fa92 (diff)
downloadchrome-ec-ccea4b67f2e36a505ddf546bde284f75d728add0.tar.gz
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 <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/961303 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/battery/max17055.c10
1 files changed, 9 insertions, 1 deletions
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, &reg);
+ if (!rv)
+ *count = CYCLE_COUNT_CONV(reg);
+ return rv;
}
int battery_design_capacity(int *capacity)