summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2018-06-29 18:23:37 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-07-17 01:43:17 +0000
commit91171747b4ca01ac929186c96d4d6aa3489c60ab (patch)
treeae19225ce8c7ff7859b65731e4824b852358f2f5
parenta7ad347585dd305ea55e6a0d7f8fd97f58ebfb33 (diff)
downloadchrome-ec-91171747b4ca01ac929186c96d4d6aa3489c60ab.tar.gz
scarlet: Cut off battery in a custom battery condition
We want to shut down AP when the battery charge drops below BATTERY_LEVEL_SHUTDOWN. Then we want to cut off the battery to protect the battery from over-discharging. But we don't want to cut off the battery right after the battery charge drops below BATTERY_LEVEL_SHUTDOWN so that we can retain the RTC timestamp for functionality reasons. So let's add a custom check before we move on to cut off the battery in shutdown_on_critical_battery(). BUG=b:68723854 BRANCH=scarlet TEST=keep the battery discharging, see AP shut down when battery charge hits 2% and later EC cut off battery when battery voltage hits 3.2V Change-Id: I9950cf32558c11a2f55ee6ca64c157146d449110 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/1121593 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Trybot-Ready: Philip Chen <philipchen@chromium.org>
-rw-r--r--board/scarlet/board.h5
-rw-r--r--common/charge_state_v2.c19
-rw-r--r--include/config.h15
3 files changed, 27 insertions, 12 deletions
diff --git a/board/scarlet/board.h b/board/scarlet/board.h
index a6120be824..b164dfa752 100644
--- a/board/scarlet/board.h
+++ b/board/scarlet/board.h
@@ -120,6 +120,11 @@
#define CONFIG_USBC_VCONN_SWAP
#define CONFIG_USB_PD_COMM_LOCKED
+#define CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF
+#undef CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION
+#define CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION \
+ ((curr.batt.flags & BATT_FLAG_BAD_VOLTAGE) || \
+ (curr.batt.voltage <= BAT_LOW_VOLTAGE_THRESH))
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_PRESENT_CUSTOM
#define CONFIG_BATTERY_RETRY_NACK
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index a02b35189b..b274712deb 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1141,10 +1141,13 @@ static inline int battery_too_low(void)
}
-/*
- * Send host event to the AP if the battery is temperature or charge level
- * is critical. Force-shutdown if the problem isn't corrected after timeout.
- */
+ /*
+ * If the battery is at extremely low charge (and discharging) or extremely
+ * high temperature, the EC will notify the AP and start a timer. If the
+ * critical condition is not corrected before the timeout expires, the EC
+ * will shut down the AP (if the AP is not already off) and then optionally
+ * hibernate or cut off battery.
+ */
static int shutdown_on_critical_battery(void)
{
int batt_temp_c;
@@ -1184,9 +1187,11 @@ static int shutdown_on_critical_battery(void)
if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
/* Timeout waiting for charger to provide more power */
#if defined(CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF)
- CPRINTS(
- "charge force battery cut-off due to critical level");
- board_cut_off_battery();
+ if (CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION) {
+ CPRINTS("charge force battery cut-off due to "
+ "critical level");
+ board_cut_off_battery();
+ }
#elif defined(CONFIG_HIBERNATE)
CPRINTS(
"charge force EC hibernate due to critical battery");
diff --git a/include/config.h b/include/config.h
index 5e764386d4..7ccb54b364 100644
--- a/include/config.h
+++ b/include/config.h
@@ -301,11 +301,10 @@
* Critical battery shutdown timeout (seconds)
*
* If the battery is at extremely low charge (and discharging) or extremely
- * high temperature, the EC will shut itself down. This defines the timeout
- * period in seconds between the critical condition being detected and the
- * EC shutting itself down. Note that if the critical condition is corrected
- * before the timeout expiration, the EC will not shut itself down.
- *
+ * high temperature, the EC will notify the AP and start a timer with the
+ * timeout defined here. If the critical condition is not corrected before
+ * the timeout expires, the EC will shut down the AP (if the AP is not already
+ * off) and then optionally hibernate or cut off battery.
*/
#define CONFIG_BATTERY_CRITICAL_SHUTDOWN_TIMEOUT 30
@@ -313,6 +312,12 @@
#undef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF
/*
+ * The extra condition we want to meet before cutting off battery
+ * when we found the battery is in a critical condition.
+ */
+#define CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION 1
+
+/*
* Support battery cut-off as host command and console command.
*
* Once defined, you have to implement a board_cut_off_battery() function