summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2018-03-29 19:45:38 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-03-31 01:56:30 -0700
commit1a3851353892f7e26182e224a3a298e8f46dfa04 (patch)
treed001800afe0db160df3b6a5bbd2c8c420476036d /driver
parent375ecebcb74efcba906b12219ac73e37d3952799 (diff)
downloadchrome-ec-1a3851353892f7e26182e224a3a298e8f46dfa04.tar.gz
battery/max17055: Report BP_NOT_SURE before battery detection finishes
After a POR, max17055 takes ~2.5 seconds to finish the detection for battery absence. Let's report BP_NOT_SURE instead of the default BP_YES when the battery detection result is not settled yet. BUG=b:72697658 BRANCH=scarlet TEST=boot scarlet w/o battery and confirm battery_is_present() never return BP_YES before reporting BP_NO Change-Id: Ia549b4b78a7403ce2c82802841b78bdd514c6200 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/989313 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Philip Chen <philipchen@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/battery/max17055.c38
-rw-r--r--driver/battery/max17055.h2
2 files changed, 37 insertions, 3 deletions
diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c
index 05a6d7a5ae..99662284a6 100644
--- a/driver/battery/max17055.c
+++ b/driver/battery/max17055.c
@@ -18,6 +18,12 @@
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
/*
+ * For max17055 to finish battery presence detection, this is the minimal time
+ * we have to wait since the last POR. LSB = 175ms.
+ */
+#define RELIABLE_BATT_DETECT_TIME 0x10
+
+/*
* Convert the register values to the units that match
* smart battery protocol.
*/
@@ -219,12 +225,38 @@ int battery_status(int *status)
enum battery_present battery_is_present(void)
{
- int status = 0;
+ int reg = 0;
+ static uint8_t batt_pres_sure;
- if (max17055_read(REG_STATUS, &status))
+ if (max17055_read(REG_STATUS, &reg))
return BP_NOT_SURE;
- if (status & STATUS_BST)
+
+ if (reg & STATUS_BST)
return BP_NO;
+
+ if (!batt_pres_sure) {
+ /*
+ * The battery detection result is not reliable within
+ * ~2.8 secs since POR.
+ */
+ if (!max17055_read(REG_TIMERH, &reg)) {
+ /*
+ * The LSB of TIMERH reg is 3.2 hrs. If the reg has a
+ * nonzero value, battery detection must have been
+ * settled.
+ */
+ if (reg) {
+ batt_pres_sure = 1;
+ return BP_YES;
+ }
+ if (!max17055_read(REG_TIMER, &reg) &&
+ ((uint32_t)reg > RELIABLE_BATT_DETECT_TIME)) {
+ batt_pres_sure = 1;
+ return BP_YES;
+ }
+ }
+ return BP_NOT_SURE;
+ }
return BP_YES;
}
diff --git a/driver/battery/max17055.h b/driver/battery/max17055.h
index be070e9896..5a3764d9de 100644
--- a/driver/battery/max17055.h
+++ b/driver/battery/max17055.h
@@ -37,12 +37,14 @@
#define REG_TEMPCO 0x39
#define REG_EMPTY_VOLTAGE 0x3a
#define REG_FSTAT 0x3d
+#define REG_TIMER 0x3e
#define REG_QR_TABLE30 0x42
#define REG_DQACC 0x45
#define REG_DPACC 0x46
#define REG_STATUS2 0xb0
#define REG_HIBCFG 0xba
#define REG_CONFIG2 0xbb
+#define REG_TIMERH 0xbe
#define REG_MODELCFG 0xdb
/* Status reg (0x00) flags */