diff options
Diffstat (limited to 'board/eve/battery.c')
-rw-r--r-- | board/eve/battery.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/board/eve/battery.c b/board/eve/battery.c index c9dca4abb0..84d13244bc 100644 --- a/board/eve/battery.c +++ b/board/eve/battery.c @@ -7,21 +7,25 @@ #include "battery.h" #include "battery_smart.h" +#include "bd9995x.h" #include "charge_state.h" #include "console.h" #include "ec_commands.h" #include "extpower.h" +#include "gpio.h" #include "util.h" /* Shutdown mode parameter to write to manufacturer access register */ #define SB_SHUTDOWN_DATA 0x0010 +static enum battery_present batt_pres_prev = BP_NOT_SURE; + /* Battery info for proto */ static const struct battery_info info = { .voltage_max = 8800, /* mV */ .voltage_normal = 7700, - .voltage_min = 6000, - .precharge_current = 64, /* mA */ + .voltage_min = 6100, /* Add 100mV for charger accuracy */ + .precharge_current = 256, /* mA */ .start_charging_min_c = 0, .start_charging_max_c = 46, .charging_min_c = 0, @@ -129,3 +133,54 @@ enum ec_status charger_profile_override_set_param(uint32_t param, { return EC_RES_INVALID_PARAM; } + +static inline enum battery_present battery_hw_present(void) +{ + /* The GPIO is low when the battery is physically present */ + return gpio_get_level(GPIO_BATTERY_PRESENT_L) ? BP_NO : BP_YES; +} + +static int battery_init(void) +{ + int batt_status; + + return battery_status(&batt_status) ? 0 : + !!(batt_status & STATUS_INITIALIZED); +} + +/* + * Physical detection of battery. + */ +enum battery_present battery_is_present(void) +{ + enum battery_present batt_pres; + + /* Get the physical hardware status */ + batt_pres = battery_hw_present(); + + /* + * Make sure battery status is implemented, I2C transactions are + * success & the battery status is Initialized to find out if it + * is a working battery and it is not in the cut-off mode. + * + * If battery I2C fails but VBATT is high, battery is booting from + * cut-off mode. + * + * FETs are turned off after Power Shutdown time. + * The device will wake up when a voltage is applied to PACK. + * Battery status will be inactive until it is initialized. + */ + if (batt_pres == BP_YES && batt_pres_prev != batt_pres && + !battery_is_cut_off() && !battery_init()) { + batt_pres = BP_NO; + } + + batt_pres_prev = batt_pres; + + return batt_pres; +} + +int board_battery_initialized(void) +{ + return battery_hw_present() == batt_pres_prev; +} |