diff options
author | Peter Marheine <pmarheine@chromium.org> | 2022-09-30 11:16:49 +1000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-06 03:52:22 +0000 |
commit | 829435fca35c8fa48856c13c7d48fb8a5f8c3be2 (patch) | |
tree | 79d550ac7bfcd7c1461b261ca550567eacc1ea8d | |
parent | 5cafd7515b840c573a9f4cf13b57673ec6a4eb10 (diff) | |
download | chrome-ec-829435fca35c8fa48856c13c7d48fb8a5f8c3be2.tar.gz |
sm5803: disable sinking before other reconfiguration
Silicon Mitus say that writing to flow2 enable bits when flow1 is set to an
active state (sinking or sourcing) will have no effect, and a silently
failed write like that may lead to unexpected (but not dangerous) behavior
because the enable bits will not be in the expected state. Most code paths
already satisfy this, but disabling the sink currently does not: change
sm5803_vbus_sink_enable to disable sinking before updating other
configuration, the mirror of ordering when enabling sinking.
BUG=none
TEST=nereid battery still charges/discharges as expected when PD source is
connected or disconnected
BRANCH=none
LOW_COVERAGE_REASON=no emulators currently exist for sm5803
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I50c7bf20569d7cad058c19aa238aeed8eaf2aa56
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3930177
Reviewed-by: Andrew McRae <amcrae@google.com>
-rw-r--r-- | driver/charger/sm5803.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index a6e178258f..f6d4e60eec 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -398,6 +398,17 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable) /* Last but not least, enable sinking */ rv |= sm5803_flow1_update(chgnum, CHARGER_MODE_SINK, MASK_SET); } else { + /* + * Disable sink mode, unless currently sourcing out. + * + * Writes to the FLOW2_AUTO_ENABLED bits below have no effect if + * flow1 is set to an active state, so disable sink mode first + * before making other config changes. + */ + if (!sm5803_is_sourcing_otg_power(chgnum, chgnum)) + rv |= sm5803_flow1_update(chgnum, CHARGER_MODE_SINK, + MASK_CLR); + if (chgnum == CHARGER_PRIMARY) rv |= sm5803_flow2_update( chgnum, SM5803_FLOW2_AUTO_ENABLED, MASK_CLR); @@ -415,11 +426,6 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable) regval); } #endif - - /* Disable sink mode, unless currently sourcing out */ - if (!sm5803_is_sourcing_otg_power(chgnum, chgnum)) - rv |= sm5803_flow1_update(chgnum, CHARGER_MODE_SINK, - MASK_CLR); } return rv; |