summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyushee <ayushee.shah@intel.com>2020-02-07 15:13:51 -0800
committerCommit Bot <commit-bot@chromium.org>2020-03-27 07:59:50 +0000
commitd4bc8b52d0562e1a05baea2531f735f5e3b723f4 (patch)
tree0b25cc07f59e812dc774866d1e5417081c637ff4
parent7bffc114e8f56cea32c04ac127092d29577894b8 (diff)
downloadchrome-ec-d4bc8b52d0562e1a05baea2531f735f5e3b723f4.tar.gz
usb_pd: Move cable communication functions to common file
BUG=b:148528713 BRANCH=none TEST=Verified on TCPMV1 and TCPMv2, able to get correct cable characteristics. Change-Id: I812b21c87661952bf4e86acaa194d4b136371594 Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2051628 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
-rw-r--r--common/usb_pd_alt_mode_dfp.c47
-rw-r--r--common/usb_pd_policy.c37
-rw-r--r--common/usbc/usb_pe_drp_sm.c16
-rw-r--r--fuzz/usb_tcpm_v2_fuzz.c5
-rw-r--r--include/usb_pd.h22
-rw-r--r--test/fake_usbc.c5
6 files changed, 81 insertions, 51 deletions
diff --git a/common/usb_pd_alt_mode_dfp.c b/common/usb_pd_alt_mode_dfp.c
index 1315ef1fcd..5e8abf4208 100644
--- a/common/usb_pd_alt_mode_dfp.c
+++ b/common/usb_pd_alt_mode_dfp.c
@@ -437,6 +437,53 @@ void usb_mux_set_safe_mode(int port)
ppc_set_sbu(port, 0);
}
+bool is_vdo_present(int cnt, int index)
+{
+ return cnt > index;
+}
+
+/*
+ * ############################################################################
+ *
+ * Cable communication functions
+ *
+ * ############################################################################
+ */
+enum idh_ptype get_usb_pd_cable_type(int port)
+{
+ struct pd_cable *cable = pd_get_cable_attributes(port);
+
+ return cable->type;
+}
+
+void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
+ uint16_t head)
+{
+ struct pd_cable *cable = pd_get_cable_attributes(port);
+
+ /* Get cable rev */
+ cable->rev = PD_HEADER_REV(head);
+
+ if (is_vdo_present(cnt, VDO_INDEX_IDH)) {
+ cable->type = PD_IDH_PTYPE(payload[VDO_INDEX_IDH]);
+
+ if (is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE1))
+ cable->attr.raw_value =
+ payload[VDO_INDEX_PTYPE_CABLE1];
+
+ /*
+ * Ref USB PD Spec 3.0 Pg 145. For active cable there are two
+ * VDOs. Hence storing the second VDO.
+ */
+ if (is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE2))
+ cable->attr2.raw_value =
+ payload[VDO_INDEX_PTYPE_CABLE2];
+
+ cable->is_identified = 1;
+ cable->discovery = PD_DISC_COMPLETE;
+ }
+}
+
__overridable void svdm_safe_dp_mode(int port)
{
/* make DP interface safe until configure */
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index f3417a36a6..6cb69f5bc5 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -173,11 +173,6 @@ void reset_pd_cable(int port)
cable[port].last_sop_p_p_msg_id = INVALID_MSG_ID_COUNTER;
}
-enum idh_ptype get_usb_pd_cable_type(int port)
-{
- return cable[port].type;
-}
-
union tbt_mode_resp_cable get_cable_tbt_vdo(int port)
{
/*
@@ -294,11 +289,6 @@ void disable_enter_usb4_mode(int port)
static struct pd_policy pe[CONFIG_USB_PD_PORT_MAX_COUNT];
-static int is_vdo_present(int cnt, int index)
-{
- return cnt > index;
-}
-
static void enable_transmit_sop_prime(int port)
{
if (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP))
@@ -545,33 +535,6 @@ void pd_dfp_pe_init(int port)
memset(&pe[port], 0, sizeof(struct pd_policy));
}
-static void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
- uint16_t head)
-{
- if (cable[port].is_identified)
- return;
-
- /* Get cable rev */
- cable[port].rev = PD_HEADER_REV(head);
-
- if (is_vdo_present(cnt, VDO_INDEX_IDH)) {
- cable[port].type = PD_IDH_PTYPE(payload[VDO_INDEX_IDH]);
- if (is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE1))
- cable[port].attr.raw_value =
- payload[VDO_INDEX_PTYPE_CABLE1];
- }
- /*
- * Ref USB PD Spec 3.0 Pg 145. For active cable there are two VDOs.
- * Hence storing the second VDO.
- */
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE2) &&
- cable[port].type == IDH_PTYPE_ACABLE)
- cable[port].attr2.raw_value = payload[VDO_INDEX_PTYPE_CABLE2];
-
- cable[port].is_identified = 1;
-}
-
static int dfp_discover_ident(uint32_t *payload)
{
payload[0] = VDO(USB_SID_PD, 1, CMD_DISCOVER_IDENT);
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 9c4acb15b9..e570e27ce2 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -4001,15 +4001,8 @@ static void pe_vdm_identity_request_cbl_run(int port)
* PE_SRC_VDM_Identity_ACKed and
* PE_INIT_PORT_VDM_Identity_ACKed embedded here
*/
- pe[port].cable.rev =
- PD_HEADER_REV(rx_emsg[port].header);
- pe[port].cable.type = PD_IDH_PTYPE(payload[1]);
- pe[port].cable.attr.raw_value = payload[3];
- if (cnt > 4)
- pe[port].cable.attr2.raw_value =
- payload[4];
- pe[port].cable.discovery = PD_DISC_COMPLETE;
- pe[port].cable.is_identified = 1;
+ dfp_consume_cable_response(port, cnt, payload,
+ rx_emsg[port].header);
/*
* Note: If port partner runs PD 2.0, we must
@@ -4245,11 +4238,6 @@ static void pe_vdm_request_exit(int port)
PE_CLR_FLAG(port, PE_FLAGS_INTERRUPTIBLE_AMS);
}
-enum idh_ptype get_usb_pd_cable_type(int port)
-{
- return pe[port].cable.type;
-}
-
/**
* PE_VDM_Acked
*/
diff --git a/fuzz/usb_tcpm_v2_fuzz.c b/fuzz/usb_tcpm_v2_fuzz.c
index 70a8f15f5f..d4e89fd118 100644
--- a/fuzz/usb_tcpm_v2_fuzz.c
+++ b/fuzz/usb_tcpm_v2_fuzz.c
@@ -19,3 +19,8 @@ int pd_check_vconn_swap(int port)
{
return 1;
}
+
+void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
+ uint16_t head)
+{
+}
diff --git a/include/usb_pd.h b/include/usb_pd.h
index b16000d0f6..319d3471fe 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1850,6 +1850,17 @@ enum pd_msg_type pd_msg_tx_type(int port, enum pd_data_role data_role,
void reset_pd_cable(int port);
/**
+ * Returns true if the number of data objects in the payload is greater than
+ * than the VDO index
+ *
+ * @param cnt number of data objects in payload
+ * @param index VDO Index
+ * @return True if number of data objects is greater than VDO index,
+ * false otherwise
+ */
+bool is_vdo_present(int cnt, int index);
+
+/**
* Return the type of cable attached
*
* @param port USB-C port number
@@ -1858,6 +1869,17 @@ void reset_pd_cable(int port);
enum idh_ptype get_usb_pd_cable_type(int port);
/**
+ * Stores the cable's response to discover Identity SOP' request
+ *
+ * @param port USB-C port number
+ * @param cnt number of data objects in payload
+ * @param payload payload data
+ * @param head PD packet header
+ */
+void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
+ uint16_t head);
+
+/**
* Return enter USB message payload
*
* @param port USB-C port number
diff --git a/test/fake_usbc.c b/test/fake_usbc.c
index 0438eaf97f..73c992676b 100644
--- a/test/fake_usbc.c
+++ b/test/fake_usbc.c
@@ -192,6 +192,11 @@ bool pd_is_disconnected(int port)
#endif /* !CONFIG_USB_DRP_ACC_TRYSRC && !CONFIG_USB_CTVPD */
#ifndef CONFIG_USB_DRP_ACC_TRYSRC
+void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
+ uint16_t head)
+{
+}
+
void pd_set_dual_role(int port, enum pd_dual_role_states state)
{
}