From e54818593e239ea60cde55736c4dc55864508994 Mon Sep 17 00:00:00 2001 From: David Huang Date: Wed, 26 Feb 2020 16:04:14 +0800 Subject: Juniper: Return BP_NOT_SURE when DFET status is off Make battery_is_present and battery_check_present_status overridable for customize by device. Do not return BP_NO when DFET status is off. Battery might need more charge time to wake up from shutdown. Return BP_NOT_SURE to keep charge battery. BUG=b:149971271 BRANCH=jacuzzi TEST=Insert UVP/shutdown battery and check battery resume normally. Change-Id: I68841e4e6e0457711fc4f43e6346b54805b7217c Signed-off-by: David Huang Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2091131 Reviewed-by: Eric Yilun Lin Reviewed-by: Ting Shen --- baseboard/kukui/battery_smart.c | 4 ++-- baseboard/kukui/battery_smart.h | 20 +++++++++++++++++ board/jacuzzi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 baseboard/kukui/battery_smart.h diff --git a/baseboard/kukui/battery_smart.c b/baseboard/kukui/battery_smart.c index 473b1c19ce..7a58644e53 100644 --- a/baseboard/kukui/battery_smart.c +++ b/baseboard/kukui/battery_smart.c @@ -9,12 +9,12 @@ #include "battery_fuel_gauge.h" #include "battery_smart.h" -static enum battery_present batt_pres_prev = BP_NOT_SURE; +enum battery_present batt_pres_prev = BP_NOT_SURE; /* * Physical detection of battery. */ -static enum battery_present battery_check_present_status(void) +__overridable enum battery_present battery_check_present_status(void) { enum battery_present batt_pres = BP_NOT_SURE; diff --git a/baseboard/kukui/battery_smart.h b/baseboard/kukui/battery_smart.h new file mode 100644 index 0000000000..2171bfb95d --- /dev/null +++ b/baseboard/kukui/battery_smart.h @@ -0,0 +1,20 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Battery pack vendor provided charging profile + */ + +#ifndef __CROS_EC_BATTERY_SMART_H +#define __CROS_EC_BATTERY_SMART_H + +#include "battery.h" + +/* + * Physical detection of battery. + */ +__override_proto enum battery_present battery_check_present_status(void); + +extern enum battery_present batt_pres_prev; + +#endif /* __CROS_EC_BATTERY_SMART_H */ diff --git a/board/jacuzzi/battery.c b/board/jacuzzi/battery.c index 7fd56ea7a3..4f8ae97451 100644 --- a/board/jacuzzi/battery.c +++ b/board/jacuzzi/battery.c @@ -3,6 +3,7 @@ * found in the LICENSE file. */ +#include "baseboard/kukui/battery_smart.h" #include "battery.h" #include "battery_fuel_gauge.h" #include "gpio.h" @@ -99,3 +100,51 @@ enum battery_present battery_hw_present(void) { return gpio_get_level(GPIO_EC_BATT_PRES_ODL) ? BP_NO : BP_YES; } + +/* + * Physical detection of battery. + */ +__override enum battery_present battery_check_present_status(void) +{ + enum battery_present batt_pres = BP_NOT_SURE; + +#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM + /* Get the physical hardware status */ + batt_pres = battery_hw_present(); +#endif + + /* + * If the battery is not physically connected, then no need to perform + * any more checks. + */ + if (batt_pres == BP_NO) + return batt_pres; + + /* + * If the battery is present now and was present last time we checked, + * return early. + */ + if (batt_pres == batt_pres_prev) + return batt_pres; + + /* + * Check battery disconnect status. If we are unable to read battery + * disconnect status or DFET is off, then return BP_NOT_SURE. Battery + * could be in ship mode and might require pre-charge current to wake + * it up. BP_NO is not returned here because charger state machine + * will not provide pre-charge current assuming that battery is not + * present. + */ + if (battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED) + return BP_NOT_SURE; + + /* + * Ensure that battery is: + * 1. Not in cutoff + */ + if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL) + return BP_NO; + + return batt_pres; +} + -- cgit v1.2.1