summaryrefslogtreecommitdiff
path: root/common/usbc/usb_pe_drp_sm.c
diff options
context:
space:
mode:
authorScott Collyer <scollyer@google.com>2021-02-26 09:39:27 -0800
committerCommit Bot <commit-bot@chromium.org>2021-03-20 23:27:05 +0000
commit602cf8193383c940dbf740d2dde03f9257cad9ba (patch)
tree60edbf371028425558c5d3a56eef76c3a989107e /common/usbc/usb_pe_drp_sm.c
parent2104092b713e81cae64d688290eca449924d292f (diff)
downloadchrome-ec-602cf8193383c940dbf740d2dde03f9257cad9ba.tar.gz
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 <scollyer@google.com> Change-Id: I9c5bdb77405a6075de9c5b4269213f810a20cc6c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2722989 Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common/usbc/usb_pe_drp_sm.c')
-rw-r--r--common/usbc/usb_pe_drp_sm.c16
1 files changed, 13 insertions, 3 deletions
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);