summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-11-12 11:27:16 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-20 02:44:58 +0000
commit9247f46d701541811ca9bc4fb0488ba132c8a337 (patch)
tree31469590e39568001cd84c2fed8eb4d2a6e84699
parent998ddb3f4adeb84ff6db85bdb6dab8c2baee9ff9 (diff)
downloadchrome-ec-9247f46d701541811ca9bc4fb0488ba132c8a337.tar.gz
TCPMv2: Replace charging allow list
Replace the charging allow list with a check to verify whether the partner can provide at least 27W to the DUT. This should cover existing members of the allow list, and deprecate the need to continue adding to this list. BRANCH=None BUG=b:173070679 TEST=on drawcia, verify DUT can charge from power bank, Apple 3-in-1, and servo_v4 Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Id0b516782809b6912602e9b7ab0546938e0b85ed Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2535217 Tested-by: Devin Lu <Devin.Lu@quantatw.com> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--common/usbc/usb_pe_drp_sm.c66
-rw-r--r--include/usb_pd.h6
2 files changed, 38 insertions, 34 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index f9b799f7e4..aa2eb9ad47 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -1426,59 +1426,63 @@ static void pe_send_request_msg(int port)
send_data_msg(port, TCPC_TX_SOP, PD_DATA_REQUEST);
}
-static void pe_update_pdo_flags(int port, uint32_t pdo)
+static void pe_update_src_pdo_flags(int port, int pdo_cnt, uint32_t *pdos)
{
- int charge_allowlisted;
-
- if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) {
- if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
- charge_allowlisted =
- (pd_get_power_role(port) == PD_ROLE_SINK &&
- pd_charge_from_device(
- pd_get_identity_vid(port),
- pd_get_identity_pid(port)));
- } else {
- charge_allowlisted = 0;
- }
- }
-
- /* can only parse PDO flags if type is fixed */
- if ((pdo & PDO_TYPE_MASK) != PDO_TYPE_FIXED)
+ /*
+ * Only parse PDO flags if type is fixed
+ *
+ * Note: From 6.4.1 Capabilities Message "The vSafe5V Fixed Supply
+ * Object Shall always be the first object." so hitting this condition
+ * would mean the partner is voilating spec.
+ */
+ if ((pdos[0] & PDO_TYPE_MASK) != PDO_TYPE_FIXED)
return;
- if (pdo & PDO_FIXED_DUAL_ROLE)
+ if (pdos[0] & PDO_FIXED_DUAL_ROLE)
tc_partner_dr_power(port, 1);
else
tc_partner_dr_power(port, 0);
- if (pdo & PDO_FIXED_UNCONSTRAINED)
+ if (pdos[0] & PDO_FIXED_UNCONSTRAINED)
tc_partner_unconstrainedpower(port, 1);
else
tc_partner_unconstrainedpower(port, 0);
/* Do not set USB comm if we are in an alt-mode */
if (pe[port].partner_amodes[TCPC_TX_SOP].amode_idx == 0) {
- if (pdo & PDO_FIXED_COMM_CAP)
+ if (pdos[0] & PDO_FIXED_COMM_CAP)
tc_partner_usb_comm(port, 1);
else
tc_partner_usb_comm(port, 0);
}
- if (pdo & PDO_FIXED_DATA_SWAP)
+ if (pdos[0] & PDO_FIXED_DATA_SWAP)
tc_partner_dr_data(port, 1);
else
tc_partner_dr_data(port, 0);
/*
* Treat device as a dedicated charger (meaning we should charge
- * from it) if it does not support power swap, or if it is unconstrained
- * power, or if we are a sink and the device identity matches a
- * charging allow-list.
+ * from it) if:
+ * - it does not support power swap, or
+ * - it is unconstrained power, or
+ * - it presents at least 27 W of available power
*/
if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) {
- if (!(pdo & PDO_FIXED_DUAL_ROLE) ||
- (pdo & PDO_FIXED_UNCONSTRAINED) ||
- charge_allowlisted) {
+ uint32_t max_ma, max_mv, max_pdo, max_mw;
+
+ /*
+ * Get max power that the partner offers (not necessarily what
+ * this board will request)
+ */
+ pd_find_pdo_index(pdo_cnt, pdos, PD_REV3_MAX_VOLTAGE,
+ &max_pdo);
+ pd_extract_pdo_power(max_pdo, &max_ma, &max_mv);
+ max_mw = max_ma*max_mv/1000;
+
+ if (!(pdos[0] & PDO_FIXED_DUAL_ROLE) ||
+ (pdos[0] & PDO_FIXED_UNCONSTRAINED) ||
+ max_mw >= PD_DRP_CHARGE_POWER_MIN) {
PE_CLR_FLAG(port, PE_FLAGS_PORT_PARTNER_IS_DUALROLE);
charge_manager_update_dualrole(port, CAP_DEDICATED);
} else {
@@ -2777,8 +2781,7 @@ static void pe_snk_evaluate_capability_entry(int port)
pd_set_src_caps(port, num, pdo);
- /* src cap 0 should be fixed PDO */
- pe_update_pdo_flags(port, pdo[0]);
+ pe_update_src_pdo_flags(port, num, pdo);
/* Evaluate the options based on supplied capabilities */
pd_process_source_cap(port, pe[port].src_cap_cnt, pe[port].src_caps);
@@ -5051,11 +5054,6 @@ static void pe_init_port_vdm_identity_request_run(int port)
/* PE_INIT_PORT_VDM_Identity_ACKed embedded here */
dfp_consume_identity(port, sop, cnt, payload);
- /* Evaluate whether this is an allow-listed charger */
- if (IS_ENABLED(CONFIG_CHARGE_MANAGER) &&
- pd_charge_from_device(pd_get_identity_vid(port),
- pd_get_identity_pid(port)))
- charge_manager_update_dualrole(port, CAP_DEDICATED);
break;
}
case VDM_RESULT_NAK:
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 055008efd3..640cbba7ed 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -249,6 +249,12 @@ enum pd_rx_errors {
#define PD_V_SINK_DISCONNECT_MAX 3670
/* TODO(b/149530538): Add equation for vSinkDisconnectPD */
+/* Maximum voltage in mV offered by PD 3.0 Version 2.0 Spec */
+#define PD_REV3_MAX_VOLTAGE 20000
+
+/* Power in mW at which we will automatically charge from a DRP partner */
+#define PD_DRP_CHARGE_POWER_MIN 27000
+
/* function table for entered mode */
struct amode_fx {
int (*status)(int port, uint32_t *payload);