diff options
author | Diana Z <dzigterman@chromium.org> | 2020-09-03 16:53:14 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-09-14 19:32:18 +0000 |
commit | b23f483631d9e3fe3bb2b49356462e657aaf2afe (patch) | |
tree | bb1060b15057b9e397af416da34d37cc4357ece6 /driver/charger/sm5803.c | |
parent | 456fef58c6f06ed7ed6b2334c2b1e9f4913dc49b (diff) | |
download | chrome-ec-b23f483631d9e3fe3bb2b49356462e657aaf2afe.tar.gz |
SM5803: Enable hibernate function for z-state
Enable SM5803 hibernation and restore registers after booting back from
z-state.
BRANCH=None
BUG=b:166648029
TEST=on drawlat, z-state power usage is reduced and booting after
z-state the charger chips can sink and source as expected
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I6e9f9f29a184fa6177e589b3b7810f51a1b3345b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2393225
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r-- | driver/charger/sm5803.c | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 85bd9ce081..30f9826ff6 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -527,8 +527,32 @@ static void sm5803_init(int chgnum) rv |= main_write8(chgnum, 0x1F, 0x0); } - /* Disable Ibus PROCHOT comparator */ - rv = chg_read8(chgnum, SM5803_REG_PHOT1, ®); + /* Enable LDO bits */ + rv |= main_read8(chgnum, SM5803_REG_REFERENCE, ®); + reg &= ~(BIT(0) | BIT(1)); + rv |= main_write8(chgnum, SM5803_REG_REFERENCE, reg); + + /* Set a higher clock speed in case it was lowered for z-state */ + rv |= main_read8(chgnum, SM5803_REG_CLOCK_SEL, ®); + reg &= ~SM5803_CLOCK_SEL_LOW; + rv |= main_write8(chgnum, SM5803_REG_CLOCK_SEL, reg); + + /* Turn on GPADCs to default */ + rv |= meas_write8(chgnum, SM5803_REG_GPADC_CONFIG1, 0xF3); + + /* Enable Psys DAC */ + rv |= meas_read8(chgnum, SM5803_REG_PSYS1, ®); + reg |= SM5803_PSYS1_DAC_EN; + rv |= meas_write8(chgnum, SM5803_REG_PSYS1, reg); + + /* Enable ADC sigma delta */ + rv |= chg_read8(chgnum, SM5803_REG_CC_CONFIG1, ®); + reg |= SM5803_CC_CONFIG1_SD_PWRUP; + rv |= chg_write8(chgnum, SM5803_REG_CC_CONFIG1, reg); + + /* Enable PROCHOT comparators except Ibus */ + rv |= chg_read8(chgnum, SM5803_REG_PHOT1, ®); + reg |= SM5803_PHOT1_COMPARATOR_EN; reg &= ~SM5803_PHOT1_IBUS_PHOT_COMP_EN; rv |= chg_write8(chgnum, SM5803_REG_PHOT1, reg); @@ -632,6 +656,52 @@ static enum ec_error_list sm5803_post_init(int chgnum) return EC_SUCCESS; } +void sm5803_hibernate(int chgnum) +{ + enum ec_error_list rv; + int reg; + + rv = main_read8(chgnum, SM5803_REG_REFERENCE, ®); + if (rv) { + CPRINTS("%s %d: Failed to read REFERENCE reg", CHARGER_NAME, + chgnum); + return; + } + + /* Disable LDO bits - note the primary LDO should not be disabled */ + if (chgnum != CHARGER_PRIMARY) { + reg |= (BIT(0) | BIT(1)); + rv |= main_write8(chgnum, SM5803_REG_REFERENCE, reg); + } + + /* Slow the clock speed */ + rv |= main_read8(chgnum, SM5803_REG_CLOCK_SEL, ®); + reg |= SM5803_CLOCK_SEL_LOW; + rv |= main_write8(chgnum, SM5803_REG_CLOCK_SEL, reg); + + /* Turn off GPADCs */ + rv |= meas_write8(chgnum, SM5803_REG_GPADC_CONFIG1, 0); + rv |= meas_write8(chgnum, SM5803_REG_GPADC_CONFIG2, 0); + + /* Disable Psys DAC */ + rv |= meas_read8(chgnum, SM5803_REG_PSYS1, ®); + reg &= ~SM5803_PSYS1_DAC_EN; + rv |= meas_write8(chgnum, SM5803_REG_PSYS1, reg); + + /* Disable ADC sigma delta */ + rv |= chg_read8(chgnum, SM5803_REG_CC_CONFIG1, ®); + reg &= ~SM5803_CC_CONFIG1_SD_PWRUP; + rv |= chg_write8(chgnum, SM5803_REG_CC_CONFIG1, reg); + + /* Disable PROCHOT comparators */ + rv |= chg_read8(chgnum, SM5803_REG_PHOT1, ®); + reg &= ~SM5803_PHOT1_COMPARATOR_EN; + rv |= chg_write8(chgnum, SM5803_REG_PHOT1, reg); + + if (rv) + CPRINTS("%s %d: Failed to set hibernate", CHARGER_NAME, chgnum); +} + /* * Process interrupt registers and report any Vbus changes. Alert the AP if the * charger has become too hot. |