summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2021-06-15 11:33:56 -0600
committerCommit Bot <commit-bot@chromium.org>2021-06-15 22:00:54 +0000
commit1fe26496136cdbe0ad98080236d84ef7872e2468 (patch)
tree7229ee1f1907f5f63f3a4e11eda024738e291d7e /common
parenta037fe1ac20c14c8addd0a186efda142578c081e (diff)
downloadchrome-ec-1fe26496136cdbe0ad98080236d84ef7872e2468.tar.gz
TCPMv2: Ignore PR swap requests when PR transitioning
The charge manager may request a PR swap when it is no longer charging from a port that is DRP and configured as sink. This can prevent us from depleting a tablet when there's a better charger available, for example. However, when the DRP partner has already initiated a PR swap this may lead to the chromebook inadvertently becoming the sink of the connection again. Ignore PR swap requests while we're in a state where our PR role doesn't match what it's expected to be shortly in order to prevent this. BRANCH=None BUG=b:174334068 TEST=on storo, connect guybrush and enable charging alternately from both DUTs. Then, when charging from the other DUT, connect a charger and ensure that storo swaps to sourcing the other system. Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I1908f4ee726d49ca89f6f0c8f75bdfdf0fb12a47 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2964920 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/usbc/usb_pe_drp_sm.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 58bdbd6530..2b1b97cc6f 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -1750,12 +1750,33 @@ static void pe_update_src_pdo_flags(int port, int pdo_cnt, uint32_t *pdos)
}
}
+/*
+ * Evaluate whether our PR role is in the middle of changing, meaning we our
+ * current PR role is not the one we expect to have very shortly.
+ */
+bool pe_is_pr_swapping(int port)
+{
+ enum usb_pe_state cur_state = get_state_pe(port);
+
+ if (cur_state == PE_PRS_SRC_SNK_EVALUATE_SWAP ||
+ cur_state == PE_PRS_SRC_SNK_TRANSITION_TO_OFF ||
+ cur_state == PE_PRS_SNK_SRC_EVALUATE_SWAP ||
+ cur_state == PE_PRS_SNK_SRC_TRANSITION_TO_OFF)
+ return true;
+
+ return false;
+}
+
void pd_request_power_swap(int port)
{
/* Ignore requests when the board does not wish to swap */
if (!pd_check_power_swap(port))
return;
+ /* Ignore requests when our power role is transitioning */
+ if (pe_is_pr_swapping(port))
+ return;
+
/*
* Always reset the SRC to SNK PR swap counter when a PR swap is
* requested by policy.