summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */