diff options
author | Diana Z <dzigterman@chromium.org> | 2020-11-10 16:51:39 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-18 01:00:07 +0000 |
commit | 45173bfb53014626057980a9b8911ca23002ff5a (patch) | |
tree | 979dd560326fe7bf5a03ed5817129bbd4469fcb1 /driver/charger/sm5803.c | |
parent | 867fe225cbd2321bf07241213c43692b7bf122c4 (diff) | |
download | chrome-ec-45173bfb53014626057980a9b8911ca23002ff5a.tar.gz |
SM5803: Add overcurrent reporting
Report overcurrent on OTG failure interrupt. Note that this may manifest
with no discharge status, or with a Vbus short discharge status.
BRANCH=None
BUG=b:171501161
TEST=on drawcia, connect a USB load and observe the port is shut off
after too many overcurrent events, but another port partner plugged in
will receive Vbus and Vconn. Observe that connecting a reasonable
load of less than 1.5A can succeed after a single OTG failure. Observe
sourcing out to several dongles works normally.
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I72162b32c5bacd34be599abc260b0d4156c764a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2532677
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r-- | driver/charger/sm5803.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 99e4600f7c..e4da424e1e 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -18,6 +18,7 @@ #include "timer.h" #include "usb_charge.h" #include "usb_pd.h" +#include "usbc_ocp.h" #include "util.h" #include "watchdog.h" @@ -602,7 +603,8 @@ static void sm5803_init(int chgnum) rv |= main_write8(chgnum, SM5803_REG_INT1_EN, SM5803_INT1_CHG); /* Enable end of charge interrupts for logging */ rv |= main_write8(chgnum, SM5803_REG_INT4_EN, SM5803_INT4_CHG_FAIL | - SM5803_INT4_CHG_DONE); + SM5803_INT4_CHG_DONE | + SM5803_INT4_OTG_FAIL); /* Set TINT interrupts for 360 K and 330 K */ rv |= meas_write8(chgnum, SM5803_REG_TINT_HIGH_TH, @@ -1030,6 +1032,33 @@ void sm5803_handle_interrupt(int chgnum) if (int_reg & SM5803_INT4_CHG_DONE) CPRINTS("%s %d: CHG_DONE_INT fired!!!", CHARGER_NAME, chgnum); + + if (int_reg & SM5803_INT4_OTG_FAIL) { + int status_reg; + + /* + * Gather status to detect if this was overcurrent + * + * Note: a status of 0 with this interrupt also indicates an + * overcurrent (see b/170517117) + */ + chg_read8(chgnum, SM5803_REG_STATUS_DISCHG, &status_reg); + CPRINTS("%s %d: OTG_FAIL_INT fired. Status 0x%02x", + CHARGER_NAME, chgnum, status_reg); + if ((status_reg == 0) || + (status_reg == SM5803_STATUS_DISCHG_VBUS_SHORT)) { + pd_handle_overcurrent(chgnum); + } + + /* + * Clear source mode here when status is 0, since OTG disable + * will detect us as sinking in this failure case. + */ + if (status_reg == 0) + rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE | + SM5803_FLOW1_DIRECTCHG_SRC_EN, + MASK_CLR); + } } static void sm5803_irq_deferred(void) |