summaryrefslogtreecommitdiff
path: root/common/usb_pd_policy.c
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2020-04-22 19:30:16 -0600
committerCommit Bot <commit-bot@chromium.org>2020-04-25 01:28:13 +0000
commit0392c499b633c5bfb53a61d4504b396e59671c7a (patch)
treea66589ca6e0e9119a16ce28cb9a4430fc9bcecc4 /common/usb_pd_policy.c
parentcf2c8080039060adfab42a1e33e89cce518ed33b (diff)
downloadchrome-ec-0392c499b633c5bfb53a61d4504b396e59671c7a.tar.gz
TCPMv2: Cleanup: Ensure PD_FLAGS_* are not used.
PD_FLAGS_* are TCPMv1 only, so make sure they are not used with TCPMv2. BUG=none BRANCH=none TEST=none Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I7a119c9745b0004b6067862205f185557f704cb5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2161923 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/usb_pd_policy.c')
-rw-r--r--common/usb_pd_policy.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 75ebcbd869..1230d96761 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -36,8 +36,46 @@
#define CPRINTF(format, args...)
#endif
+/*
+ * This file is currently only used for TCPMv1, and would need changes before
+ * being used for TCPMv2. One example: PD_FLAGS_* are TCPMv1 only.
+ */
+#ifndef CONFIG_USB_PD_TCPMV1
+#error This file must only be used with TCPMv1
+#endif
+
static int rw_flash_changed = 1;
+__overridable void pd_check_pr_role(int port,
+ enum pd_power_role pr_role, int flags)
+{
+ /*
+ * If partner is dual-role power and dualrole toggling is on, consider
+ * if a power swap is necessary.
+ */
+ if ((flags & PD_FLAGS_PARTNER_DR_POWER) &&
+ pd_get_dual_role(port) == PD_DRP_TOGGLE_ON) {
+ /*
+ * If we are a sink and partner is not unconstrained, then
+ * swap to become a source. If we are source and partner is
+ * unconstrained, swap to become a sink.
+ */
+ int partner_unconstrained = flags & PD_FLAGS_PARTNER_UNCONSTR;
+
+ if ((!partner_unconstrained && pr_role == PD_ROLE_SINK) ||
+ (partner_unconstrained && pr_role == PD_ROLE_SOURCE))
+ pd_request_power_swap(port);
+ }
+}
+
+__overridable void pd_check_dr_role(int port,
+ enum pd_data_role dr_role, int flags)
+{
+ /* If UFP, try to switch to DFP */
+ if ((flags & PD_FLAGS_PARTNER_DR_DATA) && dr_role == PD_ROLE_UFP)
+ pd_request_data_swap(port);
+}
+
#ifdef CONFIG_MKBP_EVENT
static int dp_alt_mode_entry_get_next_event(uint8_t *data)
{