diff options
author | Philip Chen <philipchen@google.com> | 2018-04-02 15:37:20 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-04-03 01:29:16 -0700 |
commit | d3a6a8d82e3dc957f69e02b6fbce456935725797 (patch) | |
tree | 9d16d6798c76f0abcacbd5da2161c098f2f9793d /driver | |
parent | 1ea7784b7f5e9e207168a609da89ff7138dd1e20 (diff) | |
download | chrome-ec-d3a6a8d82e3dc957f69e02b6fbce456935725797.tar.gz |
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 <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/991192
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/battery/max17055.c | 29 |
1 files changed, 23 insertions, 6 deletions
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!"); } |