summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/nami/battery.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/board/nami/battery.c b/board/nami/battery.c
index b34c5e18e8..d32a1b74ff 100644
--- a/board/nami/battery.c
+++ b/board/nami/battery.c
@@ -213,6 +213,19 @@ static int battery_init(void)
!!(batt_status & STATUS_INITIALIZED);
}
+enum battery_disconnect_grace_period {
+ BATTERY_DISCONNECT_GRACE_PERIOD_OFF,
+ BATTERY_DISCONNECT_GRACE_PERIOD_ON,
+ BATTERY_DISCONNECT_GRACE_PERIOD_OVER,
+};
+static enum battery_disconnect_grace_period disconnect_grace_period;
+
+static void battery_disconnect_timer(void)
+{
+ disconnect_grace_period = BATTERY_DISCONNECT_GRACE_PERIOD_OVER;
+}
+DECLARE_DEFERRED(battery_disconnect_timer);
+
/*
* Check for case where both XCHG and XDSG bits are set indicating that even
* though the FG can be read from the battery, the battery is not able to be
@@ -238,8 +251,29 @@ static int battery_check_disconnect_ti_bq40z50(void)
if ((data[3] & (BATTERY_DISCHARGING_DISABLED |
BATTERY_CHARGING_DISABLED)) ==
- (BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED))
- return BATTERY_DISCONNECTED;
+ (BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED)) {
+ if (oem != PROJECT_SONA)
+ return BATTERY_DISCONNECTED;
+ /*
+ * For Sona, we need a workaround to wake up a battery from
+ * cutoff. We return DISCONNECT_ERROR for the 5 seconds after
+ * the first call BP_NOT_SURE is reported to chgstv2. It will
+ * supply precharge current and wakes up the battery from
+ * cutoff. If the battery is good, we won't come back here.
+ * If not, after 5 seconds, we will return DISCONNECTED to
+ * stop charging and avoid damaging the battery.
+ */
+ if (disconnect_grace_period ==
+ BATTERY_DISCONNECT_GRACE_PERIOD_OVER)
+ return BATTERY_DISCONNECTED;
+ if (disconnect_grace_period ==
+ BATTERY_DISCONNECT_GRACE_PERIOD_OFF)
+ hook_call_deferred(&battery_disconnect_timer_data,
+ 5 * SECOND);
+ ccprintf("Battery disconnect grace period\n");
+ disconnect_grace_period = BATTERY_DISCONNECT_GRACE_PERIOD_ON;
+ return BATTERY_DISCONNECT_ERROR;
+ }
return BATTERY_NOT_DISCONNECTED;
}