diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-02-25 12:56:40 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2019-04-09 16:07:50 +0000 |
commit | 22f3fd0edb9d563152e6b1d47c2e7028fb63fafd (patch) | |
tree | 48f85b4dc9bea2731dee90716287fb805c0b9920 | |
parent | 68b80ba1349d8b690ff65dc895e56d59e53caaca (diff) | |
download | chrome-ec-22f3fd0edb9d563152e6b1d47c2e7028fb63fafd.tar.gz |
chgstv2: Allow board to set charge level for shutdown
Currently, BATTERY_LEVEL_SHUTDOWN is statically determined. This patch
allows it to be set at runtime.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/123727148
BRANCH=nami,strago,coral
TEST=Verify Vayne shuts down when soc <= 4 in s0 and s5.
Change-Id: I535c451e97ebf6bc735c46d7789d4b56ed82914b
Reviewed-on: https://chromium-review.googlesource.com/1512619
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>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1518293
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 13 | ||||
-rw-r--r-- | include/charge_state_v2.h | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 5ebbdf31d9..ef7bd30980 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -71,6 +71,8 @@ static timestamp_t uvp_throttle_start_time; static int charge_request(int voltage, int current); +static uint8_t battery_level_shutdown; + /* * State for charger_task(). Here so we can reset it on a HOOK_INIT, and * because stack space is more limited than .bss @@ -1272,11 +1274,16 @@ static inline int battery_too_hot(int batt_temp_c) batt_temp_c < batt_info->discharging_min_c)); } +__attribute__((weak)) uint8_t board_set_battery_level_shutdown(void) +{ + return BATTERY_LEVEL_SHUTDOWN; +} + /* True if we know the charge is too low, or we know the voltage is too low. */ static inline int battery_too_low(void) { return ((!(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) && - curr.batt.state_of_charge < BATTERY_LEVEL_SHUTDOWN) || + curr.batt.state_of_charge < battery_level_shutdown) || (!(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE) && curr.batt.voltage <= batt_info->voltage_min)); } @@ -1542,6 +1549,8 @@ void charger_task(void *u) curr.desired_input_current = get_desired_input_current( curr.batt.is_present, info); + battery_level_shutdown = board_set_battery_level_shutdown(); + while (1) { /* Let's see what's going on... */ @@ -1938,7 +1947,7 @@ int charge_want_shutdown(void) { return (curr.state == ST_DISCHARGE) && !(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) && - (curr.batt.state_of_charge < BATTERY_LEVEL_SHUTDOWN); + (curr.batt.state_of_charge < battery_level_shutdown); } int charge_prevent_power_on(int power_button_pressed) diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h index 4bf0d6a776..800ba4e1cd 100644 --- a/include/charge_state_v2.h +++ b/include/charge_state_v2.h @@ -126,4 +126,13 @@ enum critical_shutdown { enum critical_shutdown board_critical_shutdown_check( struct charge_state_data *curr); +/** + * Callback to set battery level for shutdown + * + * A board can implement this to customize shutdown battery level at runtime. + * + * @return battery level for shutdown + */ +uint8_t board_set_battery_level_shutdown(void); + #endif /* __CROS_EC_CHARGE_STATE_V2_H */ |