summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-02-25 12:56:40 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2019-03-05 23:31:54 +0000
commitacf0191cb3e3adf5651c5b0560975f9e2f2f8d28 (patch)
treee0f7b2fde1e20000ee31d797411bb010de899647
parentbc44f8d2928ac8df8abb57db4282fa44516b0aa0 (diff)
downloadchrome-ec-acf0191cb3e3adf5651c5b0560975f9e2f2f8d28.tar.gz
chgstv2: Make board_critical_shutdown_check specify action on critical soc
Currently, board_critical_shutdown_check is used only in the context of CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF. It returns true to cutoff the battery or false to take no action. This patch extends board_critical_shutdown_check to allow it to control what actions to take on critical battery condition. With this change, each board can also customize critical battery actions with more granularity (per OEM, BOARD_VERSION, etc.). Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/123727148 BRANCH=nami TEST=Verify a battery is cutoff at critical low charge on Scarlet and DUT wakes up by AC plugin on cros/firmware-scarlet-10388.B. Change-Id: Id49e860b05e21c3bfa4d75f27c48b55c2a3ad95f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1504075 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/scarlet/board.c10
-rw-r--r--common/charge_state_v2.c34
-rw-r--r--include/charge_state_v2.h18
-rw-r--r--test/sbs_charging_v2.c5
4 files changed, 57 insertions, 10 deletions
diff --git a/board/scarlet/board.c b/board/scarlet/board.c
index fb40b6d0cf..cf061a9b8c 100644
--- a/board/scarlet/board.c
+++ b/board/scarlet/board.c
@@ -140,6 +140,16 @@ void board_reset_pd_mcu(void)
{
}
+enum critical_shutdown board_critical_shutdown_check(
+ struct charge_state_data *curr)
+{
+ if ((curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) ||
+ (curr->batt.voltage <= BAT_LOW_VOLTAGE_THRESH))
+ return CRITICAL_SHUTDOWN_CUTOFF;
+ else
+ return CRITICAL_SHUTDOWN_IGNORE;
+}
+
uint16_t tcpc_get_alert_status(void)
{
uint16_t status = 0;
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 63d0acdc08..5ebbdf31d9 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1281,6 +1281,18 @@ static inline int battery_too_low(void)
curr.batt.voltage <= batt_info->voltage_min));
}
+__attribute__((weak))
+enum critical_shutdown board_critical_shutdown_check(
+ struct charge_state_data *curr)
+{
+#ifdef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF
+ return CRITICAL_SHUTDOWN_CUTOFF;
+#elif defined(CONFIG_HIBERNATE)
+ return CRITICAL_SHUTDOWN_HIBERNATE;
+#else
+ return CRITICAL_SHUTDOWN_IGNORE;
+#endif
+}
/*
* Send host event to the AP if the battery is temperature or charge level
@@ -1324,15 +1336,19 @@ static int shutdown_on_critical_battery(void)
CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US) {
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();
-#elif defined(CONFIG_HIBERNATE)
- CPRINTS(
- "charge force EC hibernate due to critical battery");
- system_hibernate(0, 0);
-#endif
+ switch (board_critical_shutdown_check(&curr)) {
+ case CRITICAL_SHUTDOWN_HIBERNATE:
+ CPRINTS("Hibernate due to critical battery");
+ system_hibernate(0, 0);
+ break;
+ case CRITICAL_SHUTDOWN_CUTOFF:
+ CPRINTS("Cutoff due to critical battery");
+ board_cut_off_battery();
+ break;
+ case CRITICAL_SHUTDOWN_IGNORE:
+ default:
+ break;
+ }
} else {
/* Timeout waiting for AP to shut down, so kill it */
CPRINTS(
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index 0819a0ea66..4bf0d6a776 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -109,5 +109,21 @@ void board_enable_base_power(int enable);
*/
void board_base_reset(void);
-#endif /* __CROS_EC_CHARGE_STATE_V2_H */
+/**
+ * Callback with which boards determine action on critical low battery
+ *
+ * The default implementation is provided in charge_state_v2.c. Overwrite it
+ * to customize it.
+ *
+ * @param curr Pointer to struct charge_state_data
+ * @return Action to take.
+ */
+enum critical_shutdown {
+ CRITICAL_SHUTDOWN_IGNORE,
+ CRITICAL_SHUTDOWN_HIBERNATE,
+ CRITICAL_SHUTDOWN_CUTOFF,
+};
+enum critical_shutdown board_critical_shutdown_check(
+ struct charge_state_data *curr);
+#endif /* __CROS_EC_CHARGE_STATE_V2_H */
diff --git a/test/sbs_charging_v2.c b/test/sbs_charging_v2.c
index e69cbdfb34..d2dde07cc4 100644
--- a/test/sbs_charging_v2.c
+++ b/test/sbs_charging_v2.c
@@ -36,6 +36,11 @@ static void reset_mocks(void)
shutdown_warning_time.val = 0ULL;
}
+int board_cut_off_battery(void)
+{
+ return EC_SUCCESS;
+}
+
void chipset_force_shutdown(void)
{
is_shutdown = 1;