From d3a6a8d82e3dc957f69e02b6fbce456935725797 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Mon, 2 Apr 2018 15:37:20 -0700 Subject: battery/max17055: Check/Reload the battery profile When the wrong battery profile is loaded into max17055, we need to be able to recover it after EC POR by reloading the correct profile. BUG=b:77491650 BRANCH=scarlet TEST=First, unplug/replug battery many times until I see the battery profile loaded is wrong (1/20). Second, make sure after a hard reset the correct battery profile is loaded. Change-Id: Iabb24fc75d31b9ce87bfb835e03549f4726903ed Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/991192 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Philip Chen --- driver/battery/max17055.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'driver/battery') diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c index 99662284a6..db8b798a3b 100644 --- a/driver/battery/max17055.c +++ b/driver/battery/max17055.c @@ -343,7 +343,7 @@ int battery_wait_for_stable(void) } /* Configured MAX17055 with the battery parameters for optimal performance. */ -static int max17055_init_config(void) +static int max17055_load_batt_model(void) { int reg; int hib_cfg; @@ -452,15 +452,32 @@ static void max17055_init(void) return; } - if (max17055_init_config()) { + if (max17055_load_batt_model()) { CPRINTS("max17055 configuration failed!"); return; } - } - /* Clear POR bit */ - MAX17055_READ_DEBUG(REG_STATUS, ®); - MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR)); + /* Clear POR bit */ + MAX17055_READ_DEBUG(REG_STATUS, ®); + MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR)); + } else { + const struct max17055_batt_profile *config; + + config = max17055_get_batt_profile(); + MAX17055_READ_DEBUG(REG_DESIGN_CAPACITY, ®); + + /* + * Reload the battery model if the current running one + * is wrong. + */ + if (config->design_cap != reg) { + CPRINTS("max17055 reconfig..."); + if (max17055_load_batt_model()) { + CPRINTS("max17055 configuration failed!"); + return; + } + } + } CPRINTS("max17055 configuration succeeded!"); } -- cgit v1.2.1