From ce57911110baa5c3ae8a196572d274097fd19992 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Wed, 23 May 2018 12:56:03 -0700 Subject: charge_state_v2: Add a hysteresis for under-voltage throttling There is a potential loop: (1) We throttle AP when we see under-voltage. (2) VBAT bumps because throttling starts. From our experiment, AP throttling saves ~1A, and thus VBAT increases by ~80mV. (3) VBAT hasn't hit BAT_LOW_VOLTAGE_THRESH for BAT_UVP_TIMEOUT_US, so we stop throttling. (4) VBAT again drops below BAT_LOW_VOLTAGE_THRESH. (5) Go back to (1). So let's introduce a hysteresis to under-voltage throttling. We stop throttling only when we are confident that even if we stop throttling, the battery voltage will stay above BAT_LOW_VOLTAGE_THRESH. BUG=b:73050145, chromium:838754 BRANCH=scarlet TEST=manually test on scarlet Change-Id: Ic0c17a7d37d5d6ee38c7b19f9b65d17421e55cbc Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/1070568 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Nicolas Boichat --- common/charge_state_v2.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'common/charge_state_v2.c') diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 84dcd66c70..a61da91440 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -49,7 +49,7 @@ #define BAT_OCP_TIMEOUT_US (60 * SECOND) /* BAT_OCP_HYSTERESIS_PCT can be optionally overridden in board.h. */ #ifndef BAT_OCP_HYSTERESIS_PCT -#define BAT_OCP_HYSTERESIS_PCT 10 +#define BAT_OCP_HYSTERESIS_PCT 10 #endif /* BAT_OCP_HYSTERESIS_PCT */ #define BAT_OCP_HYSTERESIS \ (BAT_MAX_DISCHG_CURRENT * BAT_OCP_HYSTERESIS_PCT / 100) /* mA */ @@ -60,6 +60,12 @@ #error "CONFIG_THROTTLE_AP_ON_BAT_VOLTAGE needs CONFIG_HOSTCMD_EVENTS" #endif /* CONFIG_HOSTCMD_EVENTS */ #define BAT_UVP_TIMEOUT_US (60 * SECOND) +/* BAT_UVP_HYSTERESIS_PCT can be optionally overridden in board.h. */ +#ifndef BAT_UVP_HYSTERESIS_PCT +#define BAT_UVP_HYSTERESIS_PCT 3 +#endif /* BAT_UVP_HYSTERESIS_PCT */ +#define BAT_UVP_HYSTERESIS \ + (BAT_LOW_VOLTAGE_THRESH * BAT_UVP_HYSTERESIS_PCT / 100) /* mV */ static timestamp_t uvp_throttle_start_time; #endif /* CONFIG_THROTTLE_AP_ON_BAT_OLTAGE */ @@ -1361,11 +1367,18 @@ static void notify_host_of_low_battery_voltage(void) chipset_in_state(CHIPSET_STATE_ANY_OFF)) return; - if (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH) { - if (!uvp_throttle_start_time.val) { - throttle_ap(THROTTLE_ON, THROTTLE_SOFT, - THROTTLE_SRC_BAT_VOLTAGE); - } + if (!uvp_throttle_start_time.val && + (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH)) { + throttle_ap(THROTTLE_ON, THROTTLE_SOFT, + THROTTLE_SRC_BAT_VOLTAGE); + uvp_throttle_start_time = get_time(); + } else if (uvp_throttle_start_time.val && + (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH + + BAT_UVP_HYSTERESIS)) { + /* + * Reset the timer when we are not sure if VBAT can stay + * above BAT_LOW_VOLTAGE_THRESH after we stop throttling. + */ uvp_throttle_start_time = get_time(); } else if (uvp_throttle_start_time.val && (get_time().val > uvp_throttle_start_time.val + -- cgit v1.2.1