diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-02-25 12:56:40 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-06 06:51:30 -0800 |
commit | dcd378e1cde499fe3c33efd98bd7e737b034ff77 (patch) | |
tree | 8f8f022e28de1986e604faae0440d49ca5e7f5c9 | |
parent | f2ea9714253427c81f9d154d0502d0d10124a8d2 (diff) | |
download | chrome-ec-dcd378e1cde499fe3c33efd98bd7e737b034ff77.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/1487113
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | board/scarlet/board.c | 10 | ||||
-rw-r--r-- | board/scarlet/board.h | 2 | ||||
-rw-r--r-- | common/charge_state_v2.c | 39 | ||||
-rw-r--r-- | include/charge_state_v2.h | 19 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | test/sbs_charging_v2.c | 5 |
6 files changed, 53 insertions, 28 deletions
diff --git a/board/scarlet/board.c b/board/scarlet/board.c index 7f217bcd80..80a3a73c4e 100644 --- a/board/scarlet/board.c +++ b/board/scarlet/board.c @@ -137,10 +137,14 @@ void board_reset_pd_mcu(void) { } -int board_critical_shutdown_check(struct charge_state_data *curr) +enum critical_shutdown board_critical_shutdown_check( + struct charge_state_data *curr) { - return ((curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) || - (curr->batt.voltage <= BAT_LOW_VOLTAGE_THRESH)); + 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) diff --git a/board/scarlet/board.h b/board/scarlet/board.h index 1d7e8203de..c5698fd096 100644 --- a/board/scarlet/board.h +++ b/board/scarlet/board.h @@ -119,8 +119,6 @@ #define CONFIG_USBC_VCONN_SWAP #define CONFIG_USB_PD_COMM_LOCKED -#define CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF -#define CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION #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 bd4bb81558..b07e82022e 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1284,6 +1284,19 @@ 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 +} + /* * 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 @@ -1329,19 +1342,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) -#ifdef CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION - if (!board_critical_shutdown_check(&curr)) - return battery_critical; -#endif /* 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"); - 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 e3a43d8bcf..ec164ea507 100644 --- a/include/charge_state_v2.h +++ b/include/charge_state_v2.h @@ -110,10 +110,21 @@ void board_enable_base_power(int enable); void board_base_reset(void); /** - * Don't cut off battery in critical battery condition when this - * board-specific routine returns 0. + * 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. */ -int board_critical_shutdown_check(struct charge_state_data *curr); +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 */ +#endif /* __CROS_EC_CHARGE_STATE_V2_H */ diff --git a/include/config.h b/include/config.h index 3b0302b2ae..107a94b469 100644 --- a/include/config.h +++ b/include/config.h @@ -378,12 +378,6 @@ #undef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF /* - * There is an extra condition we want to meet before cutting off battery - * when we found the battery is in a critical condition. - */ -#undef CONFIG_BATTERY_CRITICAL_CUT_OFF_CUSTOM_CONDITION - -/* * Support battery cut-off as host command and console command. * * Once defined, you have to implement a board_cut_off_battery() function diff --git a/test/sbs_charging_v2.c b/test/sbs_charging_v2.c index e266e59215..a41c8205d5 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(enum chipset_shutdown_reason reason) { is_shutdown = 1; |