From b07a5908e01021b9d32bf50d1a4b9720845b1cd1 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2782372 Tested-by: Abe Levkoy Reviewed-by: Abe Levkoy Commit-Queue: Abe Levkoy --- common/usbc/usb_pe_drp_sm.c | 16 +++++++++++++--- include/usb_pd.h | 11 +++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index fe172c06ed..c79c3ac4bf 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); diff --git a/include/usb_pd.h b/include/usb_pd.h index 3526adf716..7e4b2fadef 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1607,6 +1607,17 @@ void pd_vbus_low(int port); */ __override_proto int pd_check_power_swap(int port); +/** + * Check if we are allowed to automatically be charging from port partner + * + * @param port USB-C port number + * @pdo_cnt number of source cap PDOs + * @*pdos pointer to source cap PDOs + * @return True if port partner can supply power + */ +__override_proto bool pd_can_source_from_device(int port, const int pdo_cnt, + const uint32_t *pdos); + /** * Check if data swap is allowed. * -- cgit v1.2.1