summaryrefslogtreecommitdiff
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
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>
-rw-r--r--common/usbc/usb_pe_drp_sm.c16
-rw-r--r--include/usb_pd.h11
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 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);
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 534e0b7ceb..3337a9aa5c 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1608,6 +1608,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.
*
* @param port USB-C port number