From 602cf8193383c940dbf740d2dde03f9257cad9ba Mon Sep 17 00:00:00 2001 From: Scott Collyer Date: Fri, 26 Feb 2021 09:39:27 -0800 Subject: TCPMv2: PE: Add mechanism to request source power role This CL makes the function pd_can_source_from_device() overridable. This default implementation is used in deciding whether to request a power role swap. By making this overridable, boards have the option of implementing custom per port policy for requesting power role swaps. BUG=b:182441965 BRANCH=None TEST=verfied that on quiche when attaching as a sink that a power role swap request is generated. Previously, quiche relied on the host requesting a power role swap. Signed-off-by: Scott Collyer Change-Id: I9c5bdb77405a6075de9c5b4269213f810a20cc6c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2722989 Commit-Queue: Scott Collyer Tested-by: Scott Collyer Reviewed-by: Diana Z --- common/usbc/usb_pe_drp_sm.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'common/usbc') diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index e3c3ee4627..e8610f3c75 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -1213,7 +1213,7 @@ void pe_got_soft_reset(int port) set_state_pe(port, PE_SOFT_RESET); } -static bool pd_can_source_from_device(int port, const int pdo_cnt, +__overridable bool pd_can_source_from_device(int port, const int pdo_cnt, const uint32_t *pdos) { /* @@ -1748,6 +1748,13 @@ static void pe_update_src_pdo_flags(int port, int pdo_cnt, uint32_t *pdos) charge_manager_update_dualrole(port, CAP_DUALROLE); } } + + /* + * If port policy preference is to be a power role source, then request + * a power role swap. + */ + if (!pd_can_source_from_device(port, pdo_cnt, pdos)) + pd_request_power_swap(port); } void pd_request_power_swap(int port) @@ -3078,9 +3085,12 @@ static void pe_snk_evaluate_capability_entry(int port) set_cable_rev(port); - pd_set_src_caps(port, num, pdo); + /* Parse source caps if they have changed */ + if (pe[port].src_cap_cnt != num || + memcmp(pdo, pe[port].src_caps, num << 2)) + pe_update_src_pdo_flags(port, num, pdo); - pe_update_src_pdo_flags(port, num, pdo); + pd_set_src_caps(port, num, pdo); /* Evaluate the options based on supplied capabilities */ pd_process_source_cap(port, pe[port].src_cap_cnt, pe[port].src_caps); -- cgit v1.2.1