diff options
author | Diana Z <dzigterman@chromium.org> | 2020-05-08 16:01:02 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-14 18:40:57 +0000 |
commit | 1b9e5bf0c2768275c7b4e811b85854f4f7b5ab96 (patch) | |
tree | a69c874cc332d5ac39f7000670aa8f55e2e8c15b | |
parent | 82976779e1ee613824da39d6215bf880f6434c90 (diff) | |
download | chrome-ec-1b9e5bf0c2768275c7b4e811b85854f4f7b5ab96.tar.gz |
SM5803: Add cached vbus presence
Cache the current Vbus presence to provide a quick-access reference to
the PD task.
BRANCH=None
BUG=None
TEST=make -j buildall
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I4b90339b28d182a57dabd39725315d061b8b7336
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2191374
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | driver/charger/sm5803.c | 11 | ||||
-rw-r--r-- | driver/charger/sm5803.h | 3 |
2 files changed, 14 insertions, 0 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 3169da293c..bb7d60cbdf 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -42,6 +42,8 @@ static uint32_t irq_pending; /* Bitmask of chips with interrupts pending */ static struct mutex flow1_access_lock[CHARGER_NUM]; +static int charger_vbus[CHARGER_NUM]; + static int sm5803_is_sourcing_otg_power(int chgnum, int port); static inline enum ec_error_list chg_read8(int chgnum, int offset, int *value) @@ -86,6 +88,11 @@ static inline enum ec_error_list main_write8(int chgnum, int offset, int value) offset, value); } +int sm5803_is_vbus_present(int chgnum) +{ + return charger_vbus[chgnum]; +} + enum ec_error_list sm5803_configure_gpio0(int chgnum, enum sm5803_gpio0_modes mode, int od) { @@ -196,6 +203,8 @@ static void sm5803_init(int chgnum) */ rv = chg_write8(chgnum, SM5803_FLOW1_CHG_EN, 0); + } else { + charger_vbus[chgnum] = 1; } } else { CPRINTS("%s %d: Failed to read status during init", @@ -323,9 +332,11 @@ void sm5803_handle_interrupt(int chgnum) !sm5803_is_sourcing_otg_power(chgnum, chgnum)) { rv = meas_read8(chgnum, SM5803_REG_VBUS_MEAS_MSB, &meas_reg); if (meas_reg <= SM5803_VBUS_LOW_LEVEL) { + charger_vbus[chgnum] = 0; usb_charger_vbus_change(chgnum, 0); board_vbus_present_change(); } else if (meas_reg >= SM5803_VBUS_HIGH_LEVEL) { + charger_vbus[chgnum] = 1; usb_charger_vbus_change(chgnum, 1); board_vbus_present_change(); } else { diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h index 84b9421353..65ded1b286 100644 --- a/driver/charger/sm5803.h +++ b/driver/charger/sm5803.h @@ -236,6 +236,9 @@ enum sm5803_gpio0_modes { #define INPUT_I_MIN 0 #define INPUT_I_STEP SM5803_CURRENT_STEP +/* Expose cached Vbus presence */ +int sm5803_is_vbus_present(int chgnum); + /* Expose functions to control charger's GPIO and CHG_DET configuration */ enum ec_error_list sm5803_configure_gpio0(int chgnum, enum sm5803_gpio0_modes mode, int od); |