From 4a89dc4fd185520f65b451eb09eb62675c22d514 Mon Sep 17 00:00:00 2001 From: xiong Date: Thu, 22 Aug 2019 15:10:11 +0800 Subject: kodama: Keep max charging voltage when remove battery With adapter plugged in S0, the system will set charging current and voltage as 0V/0A once removing battery. Vsys drop to lower voltage (Vsys < 2.5V) since Vsys's loading, then system will shutdown. Keep max charging voltage as 4.4V when remove battery in S0 to not let the system to trigger under voltage (Vsys < 2.5V). BUG=b:138978212 BRANCH=master TEST=system will stay S0 state when remove battery Change-Id: I8356ee01826ad981e2701cd3674eb7cef87da0a9 Signed-off-by: Xiong Huang Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1763899 Reviewed-by: Yilun Lin --- board/kodama/battery.c | 30 ++++++++++++++++++++++++++++-- board/kodama/board.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/board/kodama/battery.c b/board/kodama/battery.c index 28086d317b..62b0c85610 100644 --- a/board/kodama/battery.c +++ b/board/kodama/battery.c @@ -16,8 +16,6 @@ #define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) -#define BAT_LEVEL_PD_LIMIT 85 - const struct board_batt_params board_battery_info[] = { [BATTERY_SIMPLO] = { .fuel_gauge = { @@ -89,6 +87,34 @@ int charger_profile_override(struct charge_state_data *curr) mt6370_charger_profile_override(curr); #endif /* CONFIG_CHARGER_MT6370 */ + if (IS_ENABLED(CONFIG_CHARGER_MAINTAIN_VBAT)) { + /* Turn charger off if it's not needed */ + if (curr->state == ST_IDLE || curr->state == ST_DISCHARGE) { + curr->requested_voltage = 0; + curr->requested_current = 0; + } + + if (!curr->batt.is_present && + curr->requested_voltage == 0 && + curr->requested_current == 0) { + const struct battery_info *batt_info = + battery_get_info(); + + /* + * b/138978212: With adapter plugged in S0, the system + * will set charging current and voltage as 0V/0A once + * removing battery. Vsys drop to lower voltage + * (Vsys < 2.5V) since Vsys's loading, then system will + * shutdown. Keep max charging voltage as 4.4V when + * remove battery in S0 to not let the system to trigger + * under voltage (Vsys < 2.5V). + */ + CPRINTS("battery disconnected"); + curr->requested_voltage = batt_info->voltage_max; + curr->requested_current = 500; + } + } + return 0; } diff --git a/board/kodama/board.h b/board/kodama/board.h index 771bf5f81e..ff71117cb9 100644 --- a/board/kodama/board.h +++ b/board/kodama/board.h @@ -35,6 +35,7 @@ #endif /* BOARD_KRANE */ #define CONFIG_CHARGER_MT6370_BACKLIGHT +#define CONFIG_CHARGER_MAINTAIN_VBAT /* Motion Sensors */ #ifdef SECTION_IS_RW -- cgit v1.2.1