summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2019-12-22 14:00:09 -0800
committerCommit Bot <commit-bot@chromium.org>2020-01-10 22:48:47 +0000
commit56404bba566db371763f93737fcafc1cfd9ca5d2 (patch)
tree65c8605cd2d2416d586eb9344dabb6c4c7ba3d60
parentbccc832b7dbc056f464d549dd5f347277670d1b3 (diff)
downloadchrome-ec-56404bba566db371763f93737fcafc1cfd9ca5d2.tar.gz
TCPMv1: Correct the TBT3 Discovery and Entry Flow
Ref: USB Type-C Cable and Connector Specification 2.0 F.2 TBT3 Discovery and Entry Flow - Corrected the TBT3 Discovery flow - Corrected the TBT3 Entry Flow - Enabled the Active cable TBT3 mode entry - Refactored TBT & Cable VDO code on TCPMv1 so that same VDO structures can be used for TCPMv2 - Corrected getting the cable version - Cleaned up the code for super speed cable detection BUG=b:146006708, b:140643923, b:147134610 BRANCH=none TEST=Make buildall -j Able to detect Thunderbolt-compatible devices on TGLRVP Change-Id: I65f82e241d0cc2187050913e7d16942fdaa0ebd4 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1981276 Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--common/usb_common.c32
-rw-r--r--common/usb_pd_policy.c315
-rw-r--r--common/usb_pd_protocol.c20
-rw-r--r--driver/retimer/bb_retimer.c6
-rw-r--r--include/usb_pd.h468
-rw-r--r--include/usb_pd_tbt.h255
-rw-r--r--include/usb_pd_vdo.h643
-rw-r--r--util/ectool.c8
8 files changed, 1146 insertions, 601 deletions
diff --git a/common/usb_common.c b/common/usb_common.c
index 4ea06f38f8..8afd3b7b64 100644
--- a/common/usb_common.c
+++ b/common/usb_common.c
@@ -694,6 +694,23 @@ __overridable int pd_custom_vdm(int port, int cnt, uint32_t *payload,
}
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
+/*
+ * Before entering into alternate mode, state of the USB-C MUX
+ * needs to be in safe mode.
+ * Ref: USB Type-C Cable and Connector Specification
+ * Section E.2.2 Alternate Mode Electrical Requirements
+ */
+void usb_mux_set_safe_mode(int port)
+{
+ usb_mux_set(port, IS_ENABLED(CONFIG_USB_MUX_VIRTUAL) ?
+ TYPEC_MUX_SAFE : TYPEC_MUX_NONE,
+ USB_SWITCH_CONNECT, pd_get_polarity(port));
+
+ /* Isolate the SBU lines. */
+ if (IS_ENABLED(CONFIG_USBC_PPC_SBU))
+ ppc_set_sbu(port, 0);
+}
+
__overridable const struct svdm_response svdm_rsp = {
.identity = NULL,
.svids = NULL,
@@ -708,13 +725,8 @@ __overridable void svdm_safe_dp_mode(int port)
/* make DP interface safe until configure */
dp_flags[port] = 0;
dp_status[port] = 0;
- usb_mux_set(port, IS_ENABLED(CONFIG_USB_MUX_VIRTUAL) ?
- TYPEC_MUX_SAFE : TYPEC_MUX_NONE,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
- /* Isolate the SBU lines. */
- if (IS_ENABLED(CONFIG_USBC_PPC_SBU))
- ppc_set_sbu(port, 0);
+ usb_mux_set_safe_mode(port);
}
__overridable int svdm_enter_dp_mode(int port, uint32_t mode_caps)
@@ -947,14 +959,6 @@ __overridable int svdm_gfu_attention(int port, uint32_t *payload)
#ifdef CONFIG_USB_PD_TBT_COMPAT_MODE
__overridable int svdm_tbt_compat_enter_mode(int port, uint32_t mode_caps)
{
- /*
- * Before entering into alternate mode, state of the USB-C MUX needs to
- * be in safe mode Ref: USB Type-C Cable and Connector Specification
- * Section E.2.2 Alternate Mode Electrical Requirements
- */
- usb_mux_set(port, IS_ENABLED(CONFIG_USB_MUX_VIRTUAL) ?
- TYPEC_MUX_SAFE : TYPEC_MUX_NONE, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
return 0;
}
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index cdce3e5390..0980597ee5 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -23,6 +23,7 @@
#include "util.h"
#include "usb_api.h"
#include "usb_common.h"
+#include "usb_mux.h"
#include "usb_pd.h"
#include "usbc_ppc.h"
#include "version.h"
@@ -205,7 +206,7 @@ enum idh_ptype get_usb_pd_mux_cable_type(int port)
return cable[port].type;
}
-struct tbt_mode_resp_cable get_cable_tbt_vdo(int port)
+union tbt_mode_resp_cable get_cable_tbt_vdo(int port)
{
/*
* Return Discover mode SOP prime response for Thunderbolt-compatible
@@ -214,7 +215,7 @@ struct tbt_mode_resp_cable get_cable_tbt_vdo(int port)
return cable[port].cable_mode_resp;
}
-struct tbt_mode_resp_device get_dev_tbt_vdo(int port)
+union tbt_mode_resp_device get_dev_tbt_vdo(int port)
{
/*
* Return Discover mode SOP response for Thunderbolt-compatible
@@ -276,34 +277,48 @@ static inline void disable_tbt_compat_mode(int port)
cable[port].flags &= ~CABLE_FLAGS_TBT_COMPAT_ENABLE;
}
+static void set_tbt_compat_mode_ready(int port)
+{
+ if (IS_ENABLED(CONFIG_USBC_SS_MUX) &&
+ IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)) {
+ /* Connect the SBU and USB lines to the connector. */
+ if (IS_ENABLED(CONFIG_USBC_PPC_SBU))
+ ppc_set_sbu(port, 1);
+
+ /* Set usb mux to Thunderbolt-compatible mode */
+ usb_mux_set(port, TYPEC_MUX_TBT_COMPAT, USB_SWITCH_CONNECT,
+ pd_get_polarity(port));
+ }
+}
+
/*
- * TODO (b/146006708): Make the below three functions independent of
- * Thunderbolt-compatible mode enabled as these USB PD 3.0 VDO responses
- * can be used to identify other cable attributes like cable speed.
+ * Ref: USB Type-C Cable and Connector Specification
+ * Figure F-1 TBT3 Discovery Flow
*/
-static bool is_cable_superspeed(int port)
+static bool is_tbt_cable_superspeed(int port)
{
- if (is_tbt_compat_enabled(port) &&
+ if (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) &&
IS_ENABLED(CONFIG_USB_PD_DECODE_SOP)) {
- /*
- * Bit 4 gives if USB SS is supported for active cables
- * for Rev 3.0
- * Ref: PD Spec 3.0 Active Cable VDO 2
- */
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- (cable[port].type == IDH_PTYPE_ACABLE))
- return !!cable[port].attr2.a2_rev30.usb_ss_support;
+ /* Product type is Active cable, hence don't check for speed */
+ if (cable[port].type == IDH_PTYPE_ACABLE)
+ return true;
- /*
- * Bits 2:0 gives USB SS support for passive cable
- * for both Rev2.0 and Rev3.0
- * Ref: PD Spec 3.0 Passive cable VDO and
- * Spec 2.0 Passive cable VDO
- *
- * For rev2.0 active cable, bits 2:0 give USB SS support
- * (Ref: spec 2.0 Passive cable VDO)
- */
- return !!(cable[port].attr.rev20.ss & USB_SS_U31_GEN2);
+ if (cable[port].type != IDH_PTYPE_PCABLE)
+ return false;
+
+ if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
+ cable[port].rev == PD_REV30)
+ return cable[port].attr.p_rev30.ss ==
+ USB_R30_SS_U32_U40_GEN1 ||
+ cable[port].attr.p_rev30.ss ==
+ USB_R30_SS_U32_U40_GEN2 ||
+ cable[port].attr.p_rev30.ss ==
+ USB_R30_SS_U40_GEN3;
+
+ return cable[port].attr.p_rev20.ss ==
+ USB_R20_SS_U31_GEN1 ||
+ cable[port].attr.p_rev20.ss ==
+ USB_R20_SS_U31_GEN1_GEN2;
}
return false;
}
@@ -311,9 +326,9 @@ static bool is_cable_superspeed(int port)
/* Check if product supports any Modal Operation (Alternate Modes) */
static bool is_modal(int port, int cnt, uint32_t *payload)
{
- return (is_tbt_compat_enabled(port) &&
+ return IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) &&
is_vdo_present(cnt, VDO_INDEX_IDH) &&
- PD_IDH_IS_MODAL(payload[VDO_INDEX_IDH]));
+ PD_IDH_IS_MODAL(payload[VDO_INDEX_IDH]);
}
static bool is_intel_svid(int port, int prev_svid_cnt)
@@ -324,7 +339,7 @@ static bool is_intel_svid(int port, int prev_svid_cnt)
* Check if SVID0 = USB_VID_INTEL
* (Ref: USB Type-C cable and connector specification, Table F-9)
*/
- if (is_tbt_compat_enabled(port)) {
+ if (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)) {
/*
* errata: All the Thunderbolt certified cables and docks
* tested have SVID1 = 0x8087
@@ -346,18 +361,17 @@ static inline bool is_tbt_compat_mode(int port, int cnt, uint32_t *payload)
* Ref: USB Type-C cable and connector specification
* F.2.5 TBT3 Device Discover Mode Responses
*/
-
- return is_tbt_compat_enabled(port) &&
- is_vdo_present(cnt, VDO_INDEX_IDH) &&
+ return is_vdo_present(cnt, VDO_INDEX_IDH) &&
PD_VDO_RESP_MODE_INTEL_TBT(payload[VDO_INDEX_IDH]);
}
-static inline void limit_cable_speed(int port)
+static inline void limit_tbt_cable_speed(int port)
{
+ /* Cable flags are cleared when cable reset is called */
cable[port].flags |= CABLE_FLAGS_TBT_COMPAT_LIMIT_SPEED;
}
-static inline bool is_limit_cable_speed(int port)
+static inline bool is_limit_tbt_cable_speed(int port)
{
return !!(cable[port].flags & CABLE_FLAGS_TBT_COMPAT_LIMIT_SPEED);
}
@@ -374,11 +388,6 @@ static void dfp_consume_identity(int port, int cnt, uint32_t *payload)
(cnt - 1) * sizeof(uint32_t));
pd_dfp_pe_init(port);
memcpy(&pe[port].identity, payload + 1, identity_size);
- /*
- * Enable Thunderbolt-compatible mode to further check if the
- * cable and the port partner support Thunderbolt-compatible mode.
- */
- enable_tbt_compat_mode(port);
switch (ptype) {
case IDH_PTYPE_AMA:
@@ -399,11 +408,15 @@ static void dfp_consume_identity(int port, int cnt, uint32_t *payload)
}
}
-static void dfp_consume_cable_response(int port, int cnt, uint32_t *payload)
+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))
@@ -416,10 +429,9 @@ static void dfp_consume_cable_response(int port, int cnt, uint32_t *payload)
*/
if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE2) &&
- cable[port].type == IDH_PTYPE_ACABLE) {
- cable[port].rev = PD_REV30;
+ cable[port].type == IDH_PTYPE_ACABLE)
cable[port].attr2.raw_value = payload[VDO_INDEX_PTYPE_CABLE2];
- }
+
cable[port].is_identified = 1;
}
@@ -586,16 +598,57 @@ uint32_t pd_dfp_enter_mode(int port, uint16_t svid, int opos)
return VDO(modep->fx->svid, 1, CMD_ENTER_MODE | VDO_OPOS(modep->opos));
}
+/*
+ * Enter Thunderbolt-compatible mode
+ * Reference: USB Type-C cable and connector specification, Release 2.0
+ *
+ * This function fills the TBT3 objects in the payload and
+ * returns the number of objects it has filled.
+ */
static int enter_tbt_compat_mode(int port, uint32_t *payload)
{
- /* If Passive cable Enter mode SOP */
- if (get_usb_pd_mux_cable_type(port) == IDH_PTYPE_PCABLE)
- disable_transmit_sop_prime(port);
+ union tbt_dev_mode_enter_cmd enter_dev_mode = {0};
+
+ /* Table F-12 TBT3 Cable Enter Mode Command */
+ payload[0] = pd_dfp_enter_mode(port, USB_VID_INTEL, 0) |
+ VDO_SVDM_VERS(VDM_VER20);
+
+ /* For TBT3 Cable Enter Mode Command, number of Objects is 1 */
+ if (is_transmit_msg_sop_prime(port))
+ return 1;
+
+ usb_mux_set_safe_mode(port);
+
+ /* Table F-13 TBT3 Device Enter Mode Command */
+ enter_dev_mode.vendor_spec_b1 =
+ cable[port].dev_mode_resp.vendor_spec_b1;
+ enter_dev_mode.vendor_spec_b0 =
+ cable[port].dev_mode_resp.vendor_spec_b0;
+ enter_dev_mode.intel_spec_b0 = cable[port].dev_mode_resp.intel_spec_b0;
+ enter_dev_mode.cable =
+ get_usb_pd_mux_cable_type(port) == IDH_PTYPE_PCABLE ?
+ TBT_ENTER_PASSIVE_CABLE : TBT_ENTER_ACTIVE_CABLE;
+
+ if (cable[port].cable_mode_resp.tbt_cable_speed == TBT_SS_TBT_GEN3) {
+ enter_dev_mode.lsrx_comm =
+ cable[port].cable_mode_resp.lsrx_comm;
+ enter_dev_mode.retimer_type =
+ cable[port].cable_mode_resp.retimer_type;
+ enter_dev_mode.tbt_cable =
+ cable[port].cable_mode_resp.tbt_cable;
+ enter_dev_mode.tbt_rounded =
+ cable[port].cable_mode_resp.tbt_rounded;
+ enter_dev_mode.tbt_cable_speed =
+ cable[port].cable_mode_resp.tbt_cable_speed;
+ } else {
+ enter_dev_mode.tbt_cable_speed = TBT_SS_U32_GEN1_GEN2;
+ }
+ enter_dev_mode.tbt_alt_mode = TBT_ALTERNATE_MODE;
- /* Enter Thunderbolt-compatible mode */
- payload[0] = pd_dfp_enter_mode(port, USB_VID_INTEL, 1);
+ payload[1] = enter_dev_mode.raw_value;
- return !!payload[0];
+ /* For TBT3 Device Enter Mode Command, number of Objects are 2 */
+ return 2;
}
static int validate_mode_request(struct svdm_amode_data *modep,
@@ -805,19 +858,21 @@ static int process_tbt_compat_discover_modes(int port, uint32_t *payload)
* Ref: USB Type-C Cable and Connector Specification, figure F-1: TBT3
* Discovery Flow and Section F.2.7 TBT3 Cable Enter Mode Command.
*/
- /*
- * TODO: Support for entering Thunderbolt-compatible mode for
- * active cables.
- */
if (is_transmit_msg_sop_prime(port)) {
/* Store Discover Mode SOP' response */
cable[port].cable_mode_resp.raw_value = payload[1];
- if (is_limit_cable_speed(port))
+ if (is_limit_tbt_cable_speed(port))
cable[port].cable_mode_resp.tbt_cable_speed =
- USB3_GEN1_USB4_GEN2;
+ TBT_SS_U32_GEN1_GEN2;
+
+ /*
+ * Enter Mode SOP' (Cable Enter Mode) is skipped for
+ * passive cables.
+ */
+ if (get_usb_pd_mux_cable_type(port) == IDH_PTYPE_PCABLE)
+ disable_transmit_sop_prime(port);
rsize = enter_tbt_compat_mode(port, payload);
- disable_transmit_sop_prime(port);
} else {
/* Store Discover Mode SOP response */
cable[port].dev_mode_resp.raw_value = payload[1];
@@ -832,7 +887,8 @@ static int process_tbt_compat_discover_modes(int port, uint32_t *payload)
}
#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
-int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
+int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
+ uint16_t head)
{
int cmd = PD_VDO_CMD(payload[0]);
int cmd_type = PD_VDO_CMDT(payload[0]);
@@ -907,29 +963,31 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
/* Received a SOP Prime Discover Ident msg */
if (is_transmit_msg_sop_prime(port)) {
/* Store cable type */
- dfp_consume_cable_response(port, cnt, payload);
+ dfp_consume_cable_response(port, cnt, payload,
+ head);
/*
- * Disable Thunderbolt-compatible mode if cable
- * doesn't support superspeed
+ * Disable Thunderbolt-compatible mode if the
+ * cable does not support superspeed
*/
- if (!is_cable_superspeed(port))
+ if (is_tbt_compat_enabled(port) &&
+ !is_tbt_cable_superspeed(port))
disable_tbt_compat_mode(port);
- disable_transmit_sop_prime(port);
rsize = dfp_discover_svids(payload);
+ disable_transmit_sop_prime(port);
/* Received a SOP Discover Ident Message */
} else if (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP)) {
dfp_consume_identity(port, cnt, payload);
- /* Send SOP' Discover Ident message */
- if (!cable[port].is_identified) {
- rsize = dfp_discover_ident(payload);
- enable_transmit_sop_prime(port);
+
/*
- * Disable Thunderbolt-compatible mode
- * if modal op not supported
+ * Enable Thunderbolt-compatible mode
+ * if the modal operation is supported
*/
- } else if (!is_modal(port, cnt, payload)) {
- disable_tbt_compat_mode(port);
+ if (is_modal(port, cnt, payload)) {
+ enable_tbt_compat_mode(port);
+ rsize = dfp_discover_ident(payload);
+ enable_transmit_sop_prime(port);
+ } else {
rsize = dfp_discover_svids(payload);
}
} else {
@@ -948,28 +1006,28 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
int prev_svid_cnt = pe[port].svid_cnt;
dfp_consume_svids(port, cnt, payload);
/*
- * Check if 0x8087 is received for Discover SVID SOP.
- * If not, disable Thunderbolt-compatible mode
* Ref: USB Type-C Cable and Connector Specification,
* figure F-1: TBT3 Discovery Flow
+ *
+ * Check if 0x8087 is received for Discover SVID SOP.
+ * If not, disable Thunderbolt-compatible mode
+ *
+ * If 0x8087 is not received for Discover SVID SOP'
+ * limit to TBT passive Gen 2 cable
*/
- if (is_intel_svid(port, prev_svid_cnt)) {
- if (!is_transmit_msg_sop_prime(port)) {
+ if (is_tbt_compat_enabled(port)) {
+ bool intel_svid =
+ is_intel_svid(port, prev_svid_cnt);
+ if (is_transmit_msg_sop_prime(port)) {
+ if (!intel_svid)
+ limit_tbt_cable_speed(port);
+ } else if (intel_svid) {
rsize = dfp_discover_svids(payload);
enable_transmit_sop_prime(port);
break;
+ } else {
+ disable_tbt_compat_mode(port);
}
- /*
- * If 0x8087 is not received for Discover SVID SOP'
- * limit to TBT passive Gen 2 cable
- * Ref: USB Type-C Cable and Connector Specification,
- * figure F-1: TBT3 Discovery Flow
- */
- } else if (is_tbt_compat_enabled(port) &&
- is_transmit_msg_sop_prime(port)) {
- limit_cable_speed(port);
- } else {
- disable_tbt_compat_mode(port);
}
rsize = dfp_discover_modes(port, payload);
@@ -978,12 +1036,14 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
break;
case CMD_DISCOVER_MODES:
dfp_consume_modes(port, cnt, payload);
- if (is_tbt_compat_mode(port, cnt, payload)) {
+ if (is_tbt_compat_enabled(port) &&
+ is_tbt_compat_mode(port, cnt, payload)) {
rsize = process_tbt_compat_discover_modes(
port, payload);
break;
}
+ disable_tbt_compat_mode(port);
rsize = dfp_discover_modes(port, payload);
/* enter the default mode for DFP */
if (!rsize) {
@@ -995,12 +1055,18 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
case CMD_ENTER_MODE:
/* No response once device (and cable) acks */
if (is_tbt_compat_enabled(port)) {
- /*
- * Update Mux state to Thunderbolt-compatible
- * mode.
- */
- set_tbt_compat_mode_ready(port);
- rsize = 0;
+ if (is_transmit_msg_sop_prime(port)) {
+ disable_transmit_sop_prime(port);
+ rsize = enter_tbt_compat_mode(port,
+ payload);
+ } else {
+ /*
+ * Update Mux state to
+ * Thunderbolt-compatible mode.
+ */
+ set_tbt_compat_mode_ready(port);
+ rsize = 0;
+ }
/*
* Continue with PD flow if Thunderbolt-compatible mode
* is disabled.
@@ -1088,7 +1154,8 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
#else
-int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
+int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
+ uint16_t head)
{
return 0;
}
@@ -1102,27 +1169,8 @@ static const char * const cable_type[] = {
};
static const char * const cable_curr[] = {
- [CABLE_CURRENT_3A] = "3A",
- [CABLE_CURRENT_5A] = "5A",
-};
-
-static const char * const cable_ss_support[] = {
- [USB_SS_U2_ONLY] = "Not supported",
- [USB_SS_U31_GEN1] = "Gen 1",
- [USB_SS_U31_GEN2] = "Gen 1 and Gen 2",
-};
-
-static const char * const vbus_max[] = {
- [CABLE_VBUS_20V] = "20V",
- [CABLE_VBUS_30V] = "30V",
- [CABLE_VBUS_40V] = "40V",
- [CABLE_VBUS_50V] = "50V",
-};
-static const char * const conn_type[] = {
- [CONNECTOR_ATYPE] = "Type A",
- [CONNECTOR_BTYPE] = "Type B",
- [CONNECTOR_CTYPE] = "Type C",
- [CONNECTOR_CAPTIVE] = "Captive",
+ [USB_VBUS_CUR_3A] = "3A",
+ [USB_VBUS_CUR_5A] = "5A",
};
static int command_cable(int argc, char **argv)
@@ -1143,24 +1191,25 @@ static int command_cable(int argc, char **argv)
ccprintf("Cable Type: ");
if (cable[port].type != IDH_PTYPE_PCABLE &&
- cable[port].type != IDH_PTYPE_ACABLE) {
+ cable[port].type != IDH_PTYPE_ACABLE) {
ccprintf("Not Emark Cable\n");
return EC_SUCCESS;
}
ccprintf("%s\n", cable_type[cable[port].type]);
+ /* Cable revision */
+ ccprintf("Cable Rev: %d.0\n", cable[port].rev + 1);
+
/*
* For rev 2.0, rev 3.0 active and passive cables have same bits for
* connector type (Bit 19:18) and current handling capability bit 6:5
*/
- ccprintf("Connector Type: %s\n",
- cable[port].attr.rev20.connector > ARRAY_SIZE(conn_type) ?
- "Invalid" : conn_type[cable[port].attr.rev20.connector]);
+ ccprintf("Connector Type: %d\n", cable[port].attr.p_rev20.connector);
- if (cable[port].attr.rev20.current) {
+ if (cable[port].attr.p_rev20.vbus_cur) {
ccprintf("Cable Current: %s\n",
- cable[port].attr.rev20.current > ARRAY_SIZE(cable_curr) ?
- "Invalid" : cable_curr[cable[port].attr.rev20.current]);
+ cable[port].attr.p_rev20.vbus_cur > ARRAY_SIZE(cable_curr) ?
+ "Invalid" : cable_curr[cable[port].attr.p_rev20.vbus_cur]);
} else
ccprintf("Cable Current: Invalid\n");
@@ -1168,38 +1217,32 @@ static int command_cable(int argc, char **argv)
* For Rev 3.0 passive cables and Rev 2.0 active and passive cables,
* USB Superspeed Signaling support have same bits 2:0
*/
- if (cable[port].type == IDH_PTYPE_PCABLE) {
- ccprintf("USB Superspeed Signaling support: %s\n",
- cable[port].attr.rev20.ss >
- ARRAY_SIZE(cable_ss_support) ? "Invalid" :
- cable_ss_support[cable[port].attr.p_rev30.ss]);
- }
+ if (cable[port].type == IDH_PTYPE_PCABLE)
+ ccprintf("USB Superspeed Signaling support: %d\n",
+ cable[port].attr.p_rev20.ss);
/*
* For Rev 3.0 active cables and Rev 2.0 active and passive cables,
* SOP" controller preset have same bit 3
*/
- if (cable[port].type == IDH_PTYPE_ACABLE) {
- ccprintf("SOP' ' Controller: %s present\n",
- cable[port].attr.rev20.controller ? "" : "Not");
- }
+ if (cable[port].type == IDH_PTYPE_ACABLE)
+ ccprintf("SOP'' Controller: %s present\n",
+ cable[port].attr.a_rev20.sop_p_p ? "" : "Not");
if (cable[port].rev == PD_REV30) {
/*
* For Rev 3.0 active and passive cables, Max Vbus vtg have
* same bits 10:9.
*/
- ccprintf("Max vbus voltage: %s\n",
- cable[port].attr.p_rev30.vbus_max >
- ARRAY_SIZE(vbus_max) ? "Invaild" :
- vbus_max[cable[port].attr.p_rev30.vbus_max]);
+ ccprintf("Max vbus voltage: %d\n",
+ 20 + 10 * cable[port].attr.p_rev30.vbus_max);
/* For Rev 3.0 Active cables */
if (cable[port].type == IDH_PTYPE_ACABLE) {
ccprintf("SS signaling: USB_SS_GEN%u\n",
- cable[port].attr2.a2_rev30.sss ? 2 : 1);
+ cable[port].attr2.a2_rev30.usb_gen ? 2 : 1);
ccprintf("Number of SS lanes supported: %u\n",
- cable[port].attr2.a2_rev30.lanes);
+ cable[port].attr2.a2_rev30.usb_lanes);
}
}
return EC_SUCCESS;
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 20403de2eb..5902154899 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -1292,7 +1292,8 @@ static void queue_vdm(int port, uint32_t *header, const uint32_t *data,
pd[port].vdm_state = VDM_STATE_READY;
}
-static void handle_vdm_request(int port, int cnt, uint32_t *payload)
+static void handle_vdm_request(int port, int cnt, uint32_t *payload,
+ uint16_t head)
{
int rlen = 0;
uint32_t *rdata;
@@ -1312,7 +1313,7 @@ static void handle_vdm_request(int port, int cnt, uint32_t *payload)
}
if (PD_VDO_SVDM(payload[0]))
- rlen = pd_svdm(port, cnt, payload, &rdata);
+ rlen = pd_svdm(port, cnt, payload, &rdata, head);
else
rlen = pd_custom_vdm(port, cnt, payload, &rdata);
@@ -1760,7 +1761,7 @@ static void handle_data_request(int port, uint16_t head,
break;
#endif
case PD_DATA_VENDOR_DEF:
- handle_vdm_request(port, cnt, payload);
+ handle_vdm_request(port, cnt, payload, head);
break;
default:
CPRINTF("C%d Unhandled data message type %d\n", port, type);
@@ -2857,15 +2858,6 @@ void pd_interrupt_handler_task(void *p)
}
#endif /* HAS_TASK_PD_INT_C0 || HAS_TASK_PD_INT_C1 || HAS_TASK_PD_INT_C2 */
-void set_tbt_compat_mode_ready(int port)
-{
- if (IS_ENABLED(CONFIG_USBC_SS_MUX) &&
- IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE))
- /* Set usb mux to Thunderbolt-compatible mode */
- usb_mux_set(port, TYPEC_MUX_TBT_COMPAT, USB_SWITCH_CONNECT,
- pd[port].polarity);
-}
-
void pd_task(void *u)
{
int head;
@@ -5411,8 +5403,8 @@ static const enum typec_mux typec_mux_map[USB_PD_CTRL_MUX_COUNT] = {
*/
static uint8_t get_pd_control_flags(int port)
{
- struct tbt_mode_resp_cable cable_resp = get_cable_tbt_vdo(port);
- struct tbt_mode_resp_device device_resp = get_dev_tbt_vdo(port);
+ union tbt_mode_resp_cable cable_resp = get_cable_tbt_vdo(port);
+ union tbt_mode_resp_device device_resp = get_dev_tbt_vdo(port);
/*
* Ref: USB Type-C Cable and Connector Specification
diff --git a/driver/retimer/bb_retimer.c b/driver/retimer/bb_retimer.c
index 8beb500d81..de53bf5bfe 100644
--- a/driver/retimer/bb_retimer.c
+++ b/driver/retimer/bb_retimer.c
@@ -113,8 +113,8 @@ static int retimer_set_state(int port, mux_state_t mux_state)
{
uint32_t set_retimer_con = 0;
uint8_t dp_pin_mode;
- struct tbt_mode_resp_cable cable_resp;
- struct tbt_mode_resp_device dev_resp;
+ union tbt_mode_resp_cable cable_resp;
+ union tbt_mode_resp_device dev_resp;
/*
* Bit 0: DATA_CONNECTION_PRESENT
@@ -217,7 +217,7 @@ static int retimer_set_state(int port, mux_state_t mux_state)
* 0 - Type-C to Type-C Cable
* 1 - Type-C Legacy TBT Adapter
*/
- if (dev_resp.tbt_adapter == TBT_ADAPTER_LEGACY)
+ if (dev_resp.tbt_adapter == TBT_ADAPTER_TBT2_LEGACY)
set_retimer_con |= BB_RETIMER_TBT_TYPE;
/*
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 7fed1d48ac..5bef019930 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -10,7 +10,9 @@
#include <stdbool.h>
#include "common.h"
+#include "usb_pd_tbt.h"
#include "usb_pd_tcpm.h"
+#include "usb_pd_vdo.h"
/* PD Host command timeout */
#define PD_HOST_COMMAND_TIMEOUT_US SECOND
@@ -479,352 +481,21 @@ enum idh_ptype {
#define VDO_PRODUCT(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff))
#define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff)
-/*
- * Cable VDO (Ref: PD Spec 2.0 Version 1.3 - Table 6-28 and 6-29)
- * ---------
- * <31:28> :: Cable HW version
- * <27:24> :: Cable FW version
- * <23:20> :: Reserved
- * <19:18> :: Type-C to Type-A/B/C (00b == A, 01 == B, 10 == C)
- * <17> :: Reserved
- * <16:13> :: Cable latency (0001 == <10ns(~1m length))
- * <12:11> :: Cable termination type (11b == both ends active VCONN req)
- * <10> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
- * <9> :: SSTX2 Directionality support
- * <8> :: SSRX1 Directionality support
- * <7> :: SSRX2 Directionality support
- * <6:5> :: Vbus current handling capability
- * <4> :: Vbus through cable (0b == no, 1b == yes)
- * <3> :: SOP" controller present? (0b == no, 1b == yes)
- * <2:0> :: USB SS Signaling support
- */
-enum usb_ss_support {
- USB_SS_U2_ONLY,
- USB_SS_U31_GEN1,
- USB_SS_U31_GEN2,
-};
-
-enum cable_outlet {
- CABLE_PLUG = 0,
- CABLE_RECEPTACLE = 1,
-};
-
-enum current_capacity {
- CABLE_CURRENT_3A = 1,
- CABLE_CURRENT_5A,
-};
-
-enum cable_dir_support {
- CABLE_FIXED,
- CABLE_CHANGEABLE,
-};
-
-enum connector_type {
- CONNECTOR_ATYPE,
- CONNECTOR_BTYPE,
- CONNECTOR_CTYPE,
- CONNECTOR_CAPTIVE,
-};
-
-struct vdo_rev20 {
- enum usb_ss_support ss: 3;
- uint32_t controller : 1;
- uint32_t vbus_cable : 1;
- enum current_capacity current : 2;
- enum cable_dir_support ssrx2 : 1;
- enum cable_dir_support ssrx1 : 1;
- enum cable_dir_support sstx2 : 1;
- enum cable_dir_support sstx1 : 1;
- uint32_t termination : 2;
- uint32_t latency : 4;
- uint32_t reserved0 : 1;
- enum connector_type connector : 2;
- uint32_t reserved1 : 4;
- uint32_t fw_version : 4;
- uint32_t hw_version : 4;
-};
-
-#define VDO_CABLE(hw, fw, cbl, lat, term, tx1d, tx2d, rx1d, rx2d, cur, vps, \
- sopp, usbss) \
- (((hw) & 0xF) << 28 | ((fw) & 0xF) << 24 | ((cbl) & 0x3) << 18 \
- | ((lat) & 0xF) << 13 | ((term) & 0x3) << 11 | ((tx1d) & 0x1) << 10 \
- | ((tx2d) & 0x1) << 9 | ((rx1d) & 0x1) << 8 | ((rx2d) & 0x1) << 7 \
- | ((cur) & 0x3) << 5 | ((vps) & 0x1) << 4 | ((sopp) & 0x1) << 3 \
- | ((usbss) & 0x7))
-
-/*
- * Passive Cable VDO (Ref: PD Spec 3.0 Version 1.2 - Table 6-35)
- * ---------
- * <31:28> :: Cable HW version
- * <27:24> :: Cable FW version
- * <23:21> :: VDO version
- * <20> :: Reserved
- * <19:18> :: Connector Type (10b == USB-C, 11b == Captive)
- * <17> :: Reserved
- * <16:13> :: Cable latency (0001 == <10ns(~1m length))
- * <12:11> :: Cable termination type (00b == VCONN not req, 01b = VCONN req)
- * <10:9> :: Maximum cable vbus voltage
- * <8:7> :: Reserved
- * <6:5> :: Vbus current handling capability
- * <4:3> :: Reserved
- * <2:0> :: USB SS Signaling support
- */
-enum max_vbus_vtg {
- CABLE_VBUS_20V,
- CABLE_VBUS_30V,
- CABLE_VBUS_40V,
- CABLE_VBUS_50V,
-};
-
-struct passive_cable_vdo_rev30 {
- enum usb_ss_support ss: 3;
- uint32_t reserved0 : 2;
- enum current_capacity current : 2;
- uint32_t reserved1 : 2;
- enum max_vbus_vtg vbus_max : 2;
- uint32_t termination : 2;
- uint32_t latency : 4;
- uint32_t reserved2 : 1;
- enum connector_type connector : 2;
- uint32_t reserved3 : 1;
- uint32_t vdo_version : 3;
- uint32_t fw_version : 4;
- uint32_t hw_version : 4;
-};
+union cable_vdo {
+ /* Passive cable VDO */
+ union passive_cable_vdo_rev20 p_rev20;
+ union passive_cable_vdo_rev30 p_rev30;
-#define PASSIVE_VDO_CABLE_REV3(hw, fw, vdover, cbl, lat, term, vbusv, \
- cur, usbss) \
- (((hw) & 0xF) << 28 | ((fw) & 0xF) << 24 | ((vdov & 0x7) << 21) \
- | ((cbl) & 0x3) << 18 | ((lat) & 0xF) << 13 | ((term) & 0x3) << 11 \
- | ((vbusv) & 0x3) << 9 | ((cur) & 0x3) << 5 | ((usbss) & 0x7))
-
-/*
- * Active Cable VDO1 (Ref: PD Spec 3.0 Version 1.2 - Table 6-36)
- * ---------
- * <31:28> :: Cable HW version
- * <27:24> :: Cable FW version
- * <23:21> :: VDO version
- * <20> :: Reserved
- * <19:18> :: Connector Type (10b == USB-C, 11b == Captive)
- * <17> :: Reserved
- * <16:13> :: Cable latency (0001 == <10ns(~1m length))
- * <12:11> :: Cable termination type (11b == both ends active VCONN req)
- * <10:9> :: Maximum cable vbus voltage
- * <8> :: SBU Supported? (0b == yes, 1b == no)
- * <7> :: SBU Type (0b == passive, 1b == active)
- * <6:5> :: Vbus current handling capability
- * <4> :: Vbus through cable (0b == no, 1b == yes)
- * <3> :: SOP" controller present? (0b == no, 1b == yes)
- * <2:0> :: Reserved
- */
-struct active_cable_vdo_rev30 {
- uint32_t reserved0 : 3;
- uint32_t controller : 1;
- uint32_t vbus_cable : 1;
- enum current_capacity current : 2;
- uint32_t sbu_type : 1;
- uint32_t sbu_support : 1;
- enum max_vbus_vtg vbus_max : 2;
- uint32_t termination : 2;
- uint32_t latency : 4;
- uint32_t reserved1 : 1;
- enum connector_type connector : 2;
- uint32_t reserved2 : 1;
- uint32_t vdo_version : 3;
- uint32_t cable_fw_version : 4;
- uint32_t cable_hw_version : 4;
-};
-#define ACTIVE_VDO1_CABLE_REV3(hw, fw, vdover, cbl, lat, term, vbusv, sbus, \
- sbut, cur, vps, sopp) \
- (((hw) & 0xF) << 28 | ((fw) & 0xF) << 24 | ((vdov) & 0x7) << 21 \
- | ((cbl) & 0x3) << 18 | ((lat) & 0xF) << 13 | ((term) & 0x3) << 11 \
- | ((vbusv) & 0x3) << 9 | ((sbus) & 0x1) << 8 | ((sbut) & 0x1) << 7 \
- | ((cur) & 0x3) << 5 | ((vps) & 0x1) << 4 | ((sopp) & 0x1) << 3)
-
-struct cable_vdo {
- union {
- struct vdo_rev20 rev20;
- struct passive_cable_vdo_rev30 p_rev30;
- struct active_cable_vdo_rev30 a_rev30;
- uint32_t raw_value;
- };
-};
-
-/*
- * Active Cable VDO2 (Ref: PD Spec 3.0 Version 1.2 - Table 6-37)
- * ---------
- * <31:24> :: Maximum operating temperature
- * <23:16> :: Shutdown temperature
- * <15> :: Reserved
- * <14:12> :: USB3 power (000 == >10mW)
- * <11> :: U3 to U0 transition
- * <10:8> :: Reserved
- * <7:6> :: USB 2.0 Hub Hops Consumed
- * <5> :: USB 2.0 Supported? (0b == yes, 1b == no)
- * <4> :: SS Supported? (0b == yes, 1b == no)
- * <3> :: SS lanes supported (0b == one, 1b == two)
- * <2> :: Reserved
- * <1:0> :: SS signaling (0b == Gen1, 01b == Gen2)
- */
-#define ACTIVE_CABLE_VDO2_CABLE_REV3(opt, sdt, usb3p, u3u0, hhc, usb2, \
- ss, ssl, sss) \
- (((opt) & 0xFF) << 24 | ((sdt) & 0xFF) << 16 | ((usb3p) & 0x7) << 12 \
- | ((u3u0) & 0x1) << 11 | ((usb2) & 0x3) << 6 | ((ss) & 0x1) << 4 \
- | ((ssl) & 0x1) << 3 | (sss) & 0x3)
-
-enum ss_signaling {
- USB_SS_SIGNAL_SS_GEN1,
- USB_SS_SIGNAL_SS_GEN2,
-};
-
-enum ss_lane_support {
- USB_SS_ONE_LANE,
- USB_SS_TWO_LANES,
-};
-
-enum u0u3_transition_mode {
- U0_U3_DIRECT,
- U0_U3_U3S,
-};
-
-enum u3_power_support {
- U3_POWER_10mW,
- U3_POWER_5_10mW,
- U3_POWER_1_5mW,
- U3_POWER_500_1000uW,
- U3_POWER_200_500uW,
- U3_POWER_50_200uW,
- U3_POWER_0_50uW,
-};
-
-struct active_cable_vdo2_rev30 {
- enum ss_signaling sss: 2;
- uint32_t reserved0 : 1;
- enum ss_lane_support lanes : 1;
- uint32_t usb_ss_support : 1;
- uint32_t usb2_support : 1;
- uint32_t usb2_hub_hops : 2;
- uint32_t reserved1 : 3;
- enum u0u3_transition_mode u0u3: 1;
- enum u3_power_support u3_power : 3;
- uint32_t reserved2: 1;
- uint32_t shutdown_temp;
- uint32_t max_operating_temp;
-};
-
-struct active_cable_vdo2 {
- union {
- struct active_cable_vdo2_rev30 a2_rev30;
- uint32_t raw_value;
- };
-};
-
-/*
- * Thunderbolt 3 Device Discover mode responses
- * (Reference: USB Type-C cable and connector specification, Table F-13)
- * -------------------------------------------------------------
- * <31> : Intel Control Vendor Specific B1 Support (0b == No, 1b == Yes)
- * <30> : Intel Control Vendor Specific B0 Support (0b == No, 1b == Yes)
- * <29:27> : Reserved
- * <26> : Intel Specific B0 Support (0b == No, 1b == Yes)
- * <25:17> : Reserved
- * <16> : TBT Adapter (0b == TBT2 Legacy, 1b == TBT3)
- * <15:0> : TBT Alternate Mode
- */
-enum tbt_adapter_type {
- TBT_ADAPTER_LEGACY,
- TBT_ADAPTER_TBT3,
-};
+ /* Active cable VDO */
+ union active_cable_vdo_rev20 a_rev20;
+ union active_cable_vdo1_rev30 a_rev30;
-enum tbt_intel_b0_type {
- TBT_INTEL_B0_NOT_SUPPORTED,
- TBT_INTEL_B0_SUPPORTED,
+ uint32_t raw_value;
};
-enum tbt_vendor_b0_type {
- TBT_VENDOR_B0_NOT_SUPPORTED,
- TBT_VENDOR_B0_SUPPORTED,
-};
-
-enum tbt_vendor_b1_type {
- TBT_VENDOR_B1_NOT_SUPPORTED,
- TBT_VENDOR_B1_SUPPORTED,
-};
-
-/* TBT Alternate Mode */
-#define PD_VDO_RESP_MODE_INTEL_TBT(x) (((x) & 0xff) == 0x0001)
-
-struct tbt_mode_resp_device {
- union {
- struct {
- uint16_t tbt_alt_mode : 16;
- enum tbt_adapter_type tbt_adapter : 1;
- uint16_t reserved0 : 9;
- enum tbt_intel_b0_type intel_spec_b0 : 1;
- uint8_t reserved1 : 3;
- enum tbt_vendor_b0_type vendor_spec_b0 : 1;
- enum tbt_vendor_b1_type vendor_spec_b1 : 1;
- };
- uint32_t raw_value;
- };
-};
-
-/*
- * Thunderbolt 3 cable Discover mode responses
- * (Reference: USB Type-C cable and connector specification, Table F-14)
- * -------------------------------------------------------------
- * <31:24> : Reserved
- * <23> : Active cable plug link training
- * (0b == bi-directional, 1b == uni-directional)
- * <22> : Re-timer (0b == Not retimer, 1b == Retimer)
- * <21> : Cable type (0b == Non-optical, 1b == Optical)
- * <20:19> : TBT Rounded Support (00b == 3rd Gen Non-Rounded TBT,
- * 01b == 3rd & 4th Gen Rounded and Non-Rounded TBT,
- * 10b...11b == Reserved)
- * <18:16> : Cable Speed (001b = USB3.2 Gen 1,
- * 010b = USB3.2 Gen 1 and USB4 Gen 2
- * 011b = USB4 Gen 3)
- * <15:0> : TBT alternate mode
- */
-enum tbt_compat_cable_speed {
- USB3_GEN1 = 1,
- USB3_GEN1_USB4_GEN2,
- USB4_GEN3,
-};
-
-enum tbt_cable_type {
- TBT_CABLE_ELECTRICAL,
- TBT_CABLE_OPTICAL,
-};
-
-enum link_lsrx_comm {
- BIDIR_LSRX_COMM,
- UNIDIR_LSRX_COMM,
-};
-
-enum tbt_compat_rounded_support {
- TBT_GEN3_NON_ROUNDED,
- TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED,
-};
-
-enum usb_retimer_type {
- USB_REDRIVER,
- USB_RETIMER,
-};
-
-struct tbt_mode_resp_cable {
- union {
- struct {
- uint16_t tbt_alt_mode : 16;
- enum tbt_compat_cable_speed tbt_cable_speed : 3;
- enum tbt_compat_rounded_support tbt_rounded : 2;
- enum tbt_cable_type tbt_cable : 1;
- enum usb_retimer_type retimer_type : 1;
- enum link_lsrx_comm lsrx_comm : 1;
- uint8_t reserved0 : 8;
- };
- uint32_t raw_value;
- };
+union active_cable_vdo2 {
+ union active_cable_vdo2_rev30 a2_rev30;
+ uint32_t raw_value;
};
/* Cable structure for storing cable attributes */
@@ -834,16 +505,16 @@ struct pd_cable {
enum idh_ptype type;
/* Cable flags. See CABLE_FLAGS_* */
uint8_t flags;
- /* Cable attribues */
- struct cable_vdo attr;
+ /* Cable attributes */
+ union cable_vdo attr;
+ /* For USB PD REV3, active cable has 2 VDOs */
+ union active_cable_vdo2 attr2;
/* Cable revision */
uint8_t rev;
- /* For USB PD REV3, active cable has 2 VDOs */
- struct active_cable_vdo2 attr2;
/* For storing Discover mode response from device */
- struct tbt_mode_resp_device dev_mode_resp;
+ union tbt_mode_resp_device dev_mode_resp;
/* For storing Discover mode response from cable */
- struct tbt_mode_resp_cable cable_mode_resp;
+ union tbt_mode_resp_cable cable_mode_resp;
};
/* Flag for sending SOP Prime packet */
@@ -852,74 +523,8 @@ struct pd_cable {
#define CABLE_FLAGS_SOP_PRIME_PRIME_ENABLE BIT(1)
/* Check if Thunderbolt-compatible mode enabled */
#define CABLE_FLAGS_TBT_COMPAT_ENABLE BIT(2)
-/* Check if Thunderbolt-compatible mode is ready */
-#define CABLE_FLAGS_TBT_COMPAT_READY BIT(3)
/* Flag to limit speed to TBT Gen 2 passive cable */
-#define CABLE_FLAGS_TBT_COMPAT_LIMIT_SPEED BIT(4)
-
-/*
- * AMA VDO
- * ---------
- * <31:28> :: Cable HW version
- * <27:24> :: Cable FW version
- * <23:12> :: SBZ
- * <11> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
- * <10> :: SSTX2 Directionality support
- * <9> :: SSRX1 Directionality support
- * <8> :: SSRX2 Directionality support
- * <7:5> :: Vconn power
- * <4> :: Vconn power required
- * <3> :: Vbus power required
- * <2:0> :: USB SS Signaling support
- */
-#define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \
- (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \
- | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \
- | ((vcpwr) & 0x3) << 5 | (vcr) << 4 | (vbr) << 3 \
- | ((usbss) & 0x7))
-
-#define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
-#define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
-
-#define AMA_VCONN_PWR_1W 0
-#define AMA_VCONN_PWR_1W5 1
-#define AMA_VCONN_PWR_2W 2
-#define AMA_VCONN_PWR_3W 3
-#define AMA_VCONN_PWR_4W 4
-#define AMA_VCONN_PWR_5W 5
-#define AMA_VCONN_PWR_6W 6
-#define AMA_USBSS_U2_ONLY 0
-#define AMA_USBSS_U31_GEN1 1
-#define AMA_USBSS_U31_GEN2 2
-#define AMA_USBSS_BBONLY 3
-
-/*
- * VPD VDO
- * ---------
- * <31:28> :: HW version
- * <27:24> :: FW version
- * <23:21> :: VDO version
- * <20:17> :: SBZ
- * <16:15> :: Maximum VBUS Voltage
- * <14:13> :: SBZ
- * <12:7> :: VBUS Impedance
- * <6:1> :: Ground Impedance
- * <0> :: Charge Through Support
- */
-#define VDO_VPD(hw, fw, vbus, vbusz, gndz, cts) \
- (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 \
- | ((vbus) & 0x3) << 15 \
- | ((vbusz) & 0x3f) << 7 \
- | ((gndz) & 0x3f) << 1 | (cts))
-
-#define VPD_MAX_VBUS_20V 0
-#define VPD_MAX_VBUS_30V 1
-#define VPD_MAX_VBUS_40V 2
-#define VPD_MAX_VBUS_50V 3
-#define VPD_VBUS_IMP(mo) ((mo + 1) >> 1)
-#define VPD_GND_IMP(mo) (mo)
-#define VPD_CTS_SUPPORTED 1
-#define VPD_CTS_NOT_SUPPORTED 0
+#define CABLE_FLAGS_TBT_COMPAT_LIMIT_SPEED BIT(3)
/*
* SVDM Discover SVIDs request -> response
@@ -933,11 +538,6 @@ struct pd_cable {
#define PD_VDO_SVID_SVID0(vdo) ((vdo) >> 16)
#define PD_VDO_SVID_SVID1(vdo) ((vdo) & 0xffff)
-#define VPD_VDO_MAX_VBUS(vdo) (((vdo) >> 15) & 0x3)
-#define VPD_VDO_VBUS_IMP(vdo) (((vdo) >> 7) & 0x3f)
-#define VPD_VDO_GND_IMP(vdo) (((vdo) >> 1) & 0x3f)
-#define VPD_VDO_CTS(vdo) ((vdo) & 1)
-
/*
* Google modes capabilities
* <31:8> : reserved
@@ -1412,6 +1012,11 @@ enum pd_cable_plug {
PD_PLUG_FROM_CABLE = 1
};
+enum cable_outlet {
+ CABLE_PLUG = 0,
+ CABLE_RECEPTACLE = 1,
+};
+
/* Vconn role */
#define PD_ROLE_VCONN_OFF 0
#define PD_ROLE_VCONN_ON 1
@@ -1852,9 +1457,11 @@ __override_proto int pd_custom_vdm(int port, int cnt, uint32_t *payload,
* @param cnt number of data objects in the payload.
* @param payload payload data.
* @param rpayload pointer to the data to send back.
+ * @param head message header
* @return if >0, number of VDOs to send back.
*/
-int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload);
+int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
+ uint16_t head);
/**
* Handle Custom VDMs for flashing.
@@ -1953,7 +1560,7 @@ enum idh_ptype get_usb_pd_mux_cable_type(int port);
* @param port USB-C port number
* @return cable mode response vdo
*/
-struct tbt_mode_resp_cable get_cable_tbt_vdo(int port);
+union tbt_mode_resp_cable get_cable_tbt_vdo(int port);
/**
* Return the response of discover mode SOP, with SVID = 0x8087
@@ -1961,7 +1568,7 @@ struct tbt_mode_resp_cable get_cable_tbt_vdo(int port);
* @param port USB-C port number
* @return device mode response vdo
*/
-struct tbt_mode_resp_device get_dev_tbt_vdo(int port);
+union tbt_mode_resp_device get_dev_tbt_vdo(int port);
/**
* Update Mux on entering Thunderbolt-compatible mode
@@ -1982,13 +1589,6 @@ enum tbt_compat_cable_speed get_tbt_cable_speed(int port);
enum tbt_compat_rounded_support get_tbt_rounded_support(int port);
/**
- * Update Mux on entering Thunderbolt mode
- *
- * @param port USB-C port number
- */
-void set_tbt_compat_mode_ready(int port);
-
-/**
* Store Device ID & RW hash of device
*
* @param port USB-C port number
@@ -2560,6 +2160,14 @@ void pd_prepare_sysjump(void);
extern int dp_flags[CONFIG_USB_PD_PORT_MAX_COUNT];
extern uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
+
+/*
+ * Configure the USB MUX in safe mode
+ *
+ * @param port The PD port number
+ */
+void usb_mux_set_safe_mode(int port);
+
/**
* Configure the pins used for DisplayPort Alternate Mode into safe state.
*
diff --git a/include/usb_pd_tbt.h b/include/usb_pd_tbt.h
new file mode 100644
index 0000000000..337b26f74d
--- /dev/null
+++ b/include/usb_pd_tbt.h
@@ -0,0 +1,255 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Thunderbolt-compatible mode header.
+ */
+
+#ifndef __CROS_EC_USB_PD_TBT_COMPAT_H
+#define __CROS_EC_USB_PD_TBT_COMPAT_H
+
+#include "usb_pd_vdo.h"
+
+/*
+ * NOTE: Throughout the file, some of the bit fields in the structures are for
+ * information purpose, they might not be actually used in the current code.
+ * When appropriate, replace the bit fields in the structures with appropriate
+ * enums.
+ */
+
+/*
+ * Reference: USB Type-C cable and connector specification, Release 2.0
+ */
+
+/*****************************************************************************/
+/*
+ * TBT3 Device Discover Identity Responses
+ */
+
+/*
+ * Table F-8 TBT3 Device Discover Identity VDO Responses
+ * -------------------------------------------------------------
+ * <31> : USB Communications Capable as USB Host
+ * 0b = No
+ * 1b = Yes
+ * <30> : USB Communications Capable as a USB Device
+ * 0b = No
+ * 1b = Yes
+ * <29:27> : Product Type (UFP)
+ * 001b = PDUSB Hub
+ * 010b = PDUSB Peripheral
+ * 101b = Alternate Mode Adapter (AMA)
+ * 110b = VCONN-Powered USB Device (VPD)
+ * <26> : Modal Operation Supported Modal Operation Supported
+ * 0b = No
+ * 1b = Yes
+ * <25:23> : Product Type (DFP)
+ * 001b = PDUSB Hub
+ * 010b = PDUSB Host
+ * 100b = Alternate Mode Controller (AMC)
+ * <22:16> : 0 Reserved
+ * <15:0> : Per vendor USB Vendor ID
+ */
+
+/*****************************************************************************/
+/*
+ * TBT3 Discover SVID Responses
+ */
+
+/*
+ * Table F-9 TBT3 Discover SVID VDO Responses
+ * -------------------------------------------------------------
+ * Note: These SVID can be in any order
+ * <31:16> : 0x8087 = Intel/TBT3 SVID 0
+ * <B15:0> : 0xFF01 = VESA DP (if supported) SVID 1
+ */
+
+/*****************************************************************************/
+/*
+ * TBT3 Device Discover Mode Responses
+ */
+
+/*
+ * Table F-10 TBT3 Device Discover Mode VDO Responses
+ * -------------------------------------------------------------
+ * <31> : Vendor specific B1
+ * 0b = Not supported
+ * 1b = Supported
+ * <30> : Vendor specific B0
+ * 0b = Not supported
+ * 1b = Supported
+ * <29:27> : Reserved
+ * <26> : Intel specific B0
+ * 0b = Not supported
+ * 1b = Supported
+ * <25:17> : Reserved
+ * <16> : TBT Adapter
+ * 0b = TBT2 Legacy Adapter
+ * 1b = TBT3 Adapter
+ * <15:0> : TBT Alternate Mode
+ * 0x0001 = TBT Mode
+ */
+enum tbt_adapter_type {
+ TBT_ADAPTER_TBT2_LEGACY,
+ TBT_ADAPTER_TBT3,
+};
+
+/* TBT Alternate Mode */
+#define TBT_ALTERNATE_MODE 0x0001
+#define PD_VDO_RESP_MODE_INTEL_TBT(x) (((x) & 0xff) == TBT_ALTERNATE_MODE)
+
+union tbt_mode_resp_device {
+ struct {
+ uint16_t tbt_alt_mode : 16;
+ enum tbt_adapter_type tbt_adapter : 1;
+ uint16_t reserved0 : 9;
+ uint8_t intel_spec_b0 : 1;
+ uint8_t reserved1 : 3;
+ uint8_t vendor_spec_b0 : 1;
+ uint8_t vendor_spec_b1 : 1;
+ };
+ uint32_t raw_value;
+};
+
+/*
+ * Table F-11 TBT3 Cable Discover Mode VDO Responses
+ * -------------------------------------------------------------
+ * <31:24> : Reserved
+ * <23> : Active Cable Plug Link Training
+ * 0 = Active with bi-directional LSRX1 communication or when Passive
+ * 1 = Active with uni-directional LSRX1 communication
+ * <22> : Re-timer
+ * 0 = Not re-timer
+ * 1 = Re-timer
+ * <21> : Cable Type
+ * 0b = Non-Optical
+ * 1b = Optical
+ * <20:19> : TBT_Rounded_Support
+ * 00b = 3rd Gen Non-Rounded TBT
+ * 01b = 3rd & 4th Gen Rounded and Non-Rounded TBT
+ * 10b..11b = Reserved
+ * <18:16> : Cable Speed
+ * 000b = Reserved
+ * 001b = USB3.1 Gen1 Cable (10 Gbps TBT support)
+ * 010b = 10 Gbps (USB 3.2 Gen1 and Gen2 passive cables)
+ * 011b = 10 Gbps and 20 Gbps (TBT 3rd Gen active cables and
+ * 20 Gbps passive cables)
+ * 100b..111b = Reserved
+ * <15:0> : TBT Alternate Mode
+ * 0x0001 = TBT Mode
+ */
+enum tbt_compat_cable_speed {
+ TBT_SS_RES_0,
+ TBT_SS_U31_GEN1,
+ TBT_SS_U32_GEN1_GEN2,
+ TBT_SS_TBT_GEN3,
+ TBT_SS_RES_4,
+ TBT_SS_RES_5,
+ TBT_SS_RES_6,
+ TBT_SS_RES_7,
+};
+
+enum tbt_cable_type {
+ TBT_CABLE_NON_OPTICAL,
+ TBT_CABLE_OPTICAL,
+};
+
+enum tbt_compat_rounded_support {
+ TBT_GEN3_NON_ROUNDED,
+ TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED,
+ TBT_ROUND_SUP_RES_2,
+ TBT_ROUND_SUP_RES_3,
+};
+
+enum usb_retimer_type {
+ USB_NOT_RETIMER,
+ USB_RETIMER,
+};
+
+enum link_lsrx_comm {
+ BIDIR_LSRX_COMM,
+ UNIDIR_LSRX_COMM,
+};
+
+union tbt_mode_resp_cable {
+ struct {
+ uint16_t tbt_alt_mode : 16;
+ enum tbt_compat_cable_speed tbt_cable_speed : 3;
+ enum tbt_compat_rounded_support tbt_rounded : 2;
+ enum tbt_cable_type tbt_cable : 1;
+ enum usb_retimer_type retimer_type : 1;
+ enum link_lsrx_comm lsrx_comm : 1;
+ uint8_t reserved0 : 8;
+ };
+ uint32_t raw_value;
+};
+
+/*****************************************************************************/
+/*
+ * TBT3 Enter Mode Command
+ */
+
+/*
+ * Table F-13 TBT3 Device Enter Mode Command SOP
+ * -------------------------------------------------------------
+ * <31> : Vendor specific B1
+ * 0 = Not supported
+ * 1 = Supported
+ * <30> : Vendor specific B0
+ * 0 = Not supported
+ * 1 = Supported
+ * <29:27> : 000b Reserved
+ * <26> : Intel specific B0
+ * 0 = Not supported
+ * 1 = Supported
+ * <25> : 0b Reserved
+ * <24> : Active_Passive
+ * 0 = Passive cable
+ * 1 = Active cable
+ * <23> : Active Cable Link Training
+ * 0 = Active with bi-directional LSRX1 communication or when Passive
+ * 1 = Active with uni-directional LSRX1 communication
+ * <22> : Re-timer
+ * 0 = Not re-timer
+ * 1 = Re-timer
+ * <21> : Cable Type
+ * 0b = Non-Optical
+ * 1b = Optical
+ * <20:19> : TBT_Rounded_Support
+ * 00b = 3rd Gen Non-Rounded TBT
+ * 01b = 3rd & 4th Gen Rounded and Non-Rounded TBT
+ * 10b..11b = Reserved
+ * <18:16> : Cable Speed
+ * 000b = Reserved
+ * 001b = USB3.1 Gen1 Cable (10 Gbps TBT support)
+ * 010b = 10 Gbps (USB 3.2 Gen1 and Gen2 passive cables)
+ * 011b = 10 Gbps and 20 Gbps (TBT 3rd Gen active cables and
+ * 20 Gbps passive cables)
+ * 100b..111b = Reserved
+ * <15:0> : TBT Alternate Mode
+ * 0x0001 = TBT Mode
+ */
+enum tbt_enter_cable_type {
+ TBT_ENTER_PASSIVE_CABLE,
+ TBT_ENTER_ACTIVE_CABLE,
+};
+
+union tbt_dev_mode_enter_cmd {
+ struct {
+ uint16_t tbt_alt_mode : 16;
+ enum tbt_compat_cable_speed tbt_cable_speed : 3;
+ enum tbt_compat_rounded_support tbt_rounded : 2;
+ enum tbt_cable_type tbt_cable : 1;
+ enum usb_retimer_type retimer_type : 1;
+ enum link_lsrx_comm lsrx_comm : 1;
+ enum tbt_enter_cable_type cable : 1;
+ uint8_t reserved0 : 1;
+ uint8_t intel_spec_b0 : 1;
+ uint8_t reserved1 : 3;
+ uint8_t vendor_spec_b0 : 1;
+ uint8_t vendor_spec_b1 : 1;
+ };
+ uint32_t raw_value;
+};
+
+#endif /* __CROS_EC_USB_PD_TBT_COMPAT_H */
diff --git a/include/usb_pd_vdo.h b/include/usb_pd_vdo.h
new file mode 100644
index 0000000000..b813bda933
--- /dev/null
+++ b/include/usb_pd_vdo.h
@@ -0,0 +1,643 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * USB-PD Cable type header.
+ */
+
+#ifndef __CROS_EC_USB_PD_VDO_H
+#define __CROS_EC_USB_PD_VDO_H
+
+/*
+ * NOTE: Throughout the file, some of the bit fields in the structures are for
+ * information purpose, they might not be actually used in the current code.
+ * When appropriate, replace the bit fields in the structures with appropriate
+ * enums.
+ */
+
+/*
+ * ############################################################################
+ *
+ * Reference: USB Power Delivery Specification Revision 3.0, Version 2.0
+ *
+ * ############################################################################
+ */
+
+/*****************************************************************************/
+/*
+ * Table 6-38 Passive Cable VDO
+ * -------------------------------------------------------------
+ * <31:28> : HW Version
+ * 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version
+ * 0000b..1111b assigned by the VID owner
+ * <23:21> : VDO Version
+ * Version Number of the VDO (not this specification Version):
+ • Version 1.0 = 000b
+ * Values 001b..111b are Reserved and Shall Not be used
+ * <20> : Reserved
+ * Shall be set to zero.
+ * <19:18> : USB Type-C plug to USB TypeC/Captive
+ * 00b = Reserved, Shall Not be used
+ * 01b = Reserved, Shall Not be used
+ * 10b = USB Type-C
+ * 11b = Captive
+ * <17> : Reserved
+ * Shall be set to zero.
+ * <16:13> : Cable Latency
+ * 0000b – Reserved, Shall Not be used
+ * 0001b – <10ns (~1m)
+ * 0010b – 10ns to 20ns (~2m)
+ * 0011b – 20ns to 30ns (~3m)
+ * 0100b – 30ns to 40ns (~4m)
+ * 0101b – 40ns to 50ns (~5m)
+ * 0110b – 50ns to 60ns (~6m)
+ * 0111b – 60ns to 70ns (~7m)
+ * 1000b – > 70ns (>~7m)
+ * 1001b..1111b Reserved, Shall Not be used
+ * Includes latency of electronics in Active Cable
+ * <12:11> : Cable Termination Type
+ * 00b = VCONN not required.
+ * Cable Plugs that only support Discover Identity Commands
+ * Shall set these bits to 00b.
+ * 01b = VCONN required
+ * 10b..11b = Reserved, Shall Not be used
+ * <10:9> : Maximum VBUS Voltage
+ * 00b – 20V
+ * 01b – 30V
+ * 10b – 40V
+ * 11b – 50V
+ * <8:7> : Reserved
+ * Shall be set to zero.
+ * <6:5> : VBUS Current Handling Capability
+ * 00b = Reserved, Shall Not be used.
+ * 01b = 3A
+ * 10b = 5A
+ * 11b = Reserved, Shall Not be used.
+ * <4:3> : Reserved
+ * Shall be set to zero.
+ * <2:0> : USB Highest Speed
+ * 000b = [USB 2.0] only, no SuperSpeed support
+ * 001b = [USB 3.2]/[USB4] Gen1
+ * 010b = [USB 3.2]/[USB4] Gen2
+ * 011b = [USB4] Gen3
+ * 100b..111b = Reserved, Shall Not be used
+ */
+
+/*
+ * Ref: USB Type-C Cable and Connector Specification 2.0
+ * Table 5-1 Certified Cables Where USB4-compatible Operation is Expected
+ * This table lists the USB-C cables those support USB4
+ */
+
+enum usb_rev30_ss {
+ USB_R30_SS_U2_ONLY,
+ USB_R30_SS_U32_U40_GEN1,
+ USB_R30_SS_U32_U40_GEN2,
+ USB_R30_SS_U40_GEN3,
+ USB_R30_SS_RES_4,
+ USB_R30_SS_RES_5,
+ USB_R30_SS_RES_6,
+ USB_R30_SS_RES_7,
+};
+
+enum usb_vbus_cur {
+ USB_VBUS_CUR_RES_0,
+ USB_VBUS_CUR_3A,
+ USB_VBUS_CUR_5A,
+ USB_VBUS_CUR_RES_3,
+};
+
+union passive_cable_vdo_rev30 {
+ struct {
+ enum usb_rev30_ss ss: 3;
+ uint8_t reserved0 : 2;
+ enum usb_vbus_cur vbus_cur : 2;
+ uint8_t reserved1 : 2;
+ uint8_t vbus_max : 2;
+ uint8_t termination : 2;
+ uint8_t latency : 4;
+ uint8_t reserved2 : 1;
+ uint8_t connector : 2;
+ uint8_t reserved3 : 1;
+ uint8_t vdo_version : 3;
+ uint8_t fw_version : 4;
+ uint8_t hw_version : 4;
+ };
+ uint32_t raw_value;
+};
+
+/*****************************************************************************/
+/*
+ * Table 6-39 Active Cable VDO 1
+ * -------------------------------------------------------------
+ * <31:28> : HW Version 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version 0000b..1111b assigned by the VID owner
+ * <23:21> : VDO Version Version Number of the VDO
+ * (not this specification Version):
+ • Version 1.3 = 011b
+ * Values 000b, 100b..111b are Reserved and Shall Not be used
+ * <20> : Reserved Shall be set to zero.
+ * <19:18> : Connector Type 00b = Reserved, Shall Not be used
+ * 01b = Reserved, Shall Not be used
+ * 10b = USB Type-C
+ * 11b = Captive
+ * <17> : Reserved Shall be set to zero.
+ * <16:13> : Cable Latency 0000b – Reserved, Shall Not be used
+ * 0001b – <10ns (~1m)
+ * 0010b – 10ns to 20ns (~2m)
+ * 0011b – 20ns to 30ns (~3m)
+ * 0100b – 30ns to 40ns (~4m)
+ * 0101b – 40ns to 50ns (~5m)
+ * 0110b – 50ns to 60ns (~6m)
+ * 0111b – 60ns to 70ns (~7m)
+ * 1000b –1000ns (~100m)
+ * 1001b –2000ns (~200m)
+ * 1010b – 3000ns (~300m)
+ * 1011b..1111b Reserved, Shall Not be used
+ * Includes latency of electronics in Active Cable
+ * <12:11> : Cable Termination Type 00b..01b = Reserved, Shall Not be used
+ * 10b = One end Active, one end passive, VCONN required
+ * 11b = Both ends Active, VCONN required
+ * <10:9> : Maximum VBUS Voltage Maximum Cable VBUS Voltage:
+ * 00b – 20V
+ * 01b – 30V
+ * 10b – 40V
+ * 11b – 50V
+ * <8> : SBU Supported
+ * 0 = SBUs connections supported
+ * 1 = SBU connections are not supported
+ * <7> : SBU Type
+ * When SBU Supported = 1 this bit Shall be Ignored
+ * When SBU Supported = 0:
+ * 0 = SBU is passive
+ * 1 = SBU is active
+ * <6:5> : VBUS Current Handling Capability
+ * When VBUS Through Cable is “No”, this field Shall be Ignored.
+ * When VBUS Though Cable is “Yes”:
+ * 00b = USB Type-C Default Current
+ * 01b = 3A
+ * 10b = 5A
+ * 11b = Reserved, Shall Not be used.
+ * <4> : VBUS Through Cable
+ * 0 = No
+ * 1 = Yes
+ * <3> : SOP” Controller Present
+ * 0 = No SOP” controller present
+ * 1 = SOP” controller present
+ * <2:0> : USB Highest Speed
+ * 000b = [USB 2.0] only, no SuperSpeed support
+ * 001b = [USB 3.2]/[USB4] Gen1
+ * 010b = [USB 3.2]/[USB4] Gen2
+ * 011b = [USB4] Gen3
+ * 100b..111b = Reserved, Shall Not be used
+ */
+union active_cable_vdo1_rev30 {
+ struct {
+ enum usb_rev30_ss ss: 3;
+ uint8_t sop_p_p : 1;
+ uint8_t vbus_cable : 1;
+ enum usb_vbus_cur vbus_cur : 2;
+ uint8_t sbu_type : 1;
+ uint8_t sbu_support : 1;
+ uint8_t vbus_max : 2;
+ uint8_t termination : 2;
+ uint8_t latency : 4;
+ uint8_t reserved0 : 1;
+ uint8_t connector : 2;
+ uint8_t reserved1 : 1;
+ uint8_t vdo_version : 3;
+ uint8_t fw_version : 4;
+ uint8_t hw_version : 4;
+ };
+ uint32_t raw_value;
+};
+
+/*****************************************************************************/
+/*
+ * Table 6-40 Active Cable VDO 2
+ * -------------------------------------------------------------
+ * <31:24> : Maximum Operating Temperature
+ * The maximum internal operating temperature.
+ * It may or may not reflect the plug’s skin temperature.
+ * <23:16> : Shutdown Temperature
+ * The temperature at which the cable will go into thermal shutdown
+ * so as not to exceed the allowable plug skin temperature.
+ * <15> : Reserved Shall be set to zero.
+ * <14:12> : U3/CLd Power 000b: >10mW
+ * 001b: 5-10mW
+ * 010b: 1-5mW
+ * 011b: 0.5-1mW
+ * 100b: 0.2-0.5mW
+ * 101b: 50-200µW
+ * 110b: <50µW
+ * 111b: Reserved, Shall Not be used
+ * <11> : U3 to U0 transition mode
+ * 0b: U3 to U0 direct
+ * 1b: U3 to U0 through U3S
+ * <10> : Physical connection
+ * 0b = Copper
+ * 1b = Optical
+ * <9> : Active element
+ * 0b = Active Redriver
+ * 1b = Active Retimer
+ * <8> : USB4 Supported
+ * 0b = [USB4] supported
+ * 1b = [USB4] not supported
+ * <7:6> : USB 2.0 Hub Hops Consumed
+ * Number of [USB 2.0] ‘hub hops’ cable consumes.
+ * Shall be set to 0 if USB 2.0 not supported.
+ * <5> : USB 2.0 Supported
+ * 0b = [USB 2.0] supported
+ * 1b = [USB 2.0] not supported
+ * <4> : USB 3.2 Supported
+ * 0b = [USB 3.2] SuperSpeed supported
+ * 1b = [USB 3.2] SuperSpeed not supported
+ * <3> : USB Lanes Supported
+ * 0b = One lane
+ * 1b = Two lanes
+ * <2> : Optically Isolated Active Cable
+ * 0b = No
+ * 1b = Yes
+ * <1> : Reserved Shall be set to zero.
+ * <0> : USB Gen
+ * 0b = Gen 1
+ * 1b = Gen 2 or higher
+ * Note: see VDO1 USB Highest Speed for details of Gen supported.
+ */
+union active_cable_vdo2_rev30 {
+ struct {
+ uint8_t usb_gen : 1;
+ uint8_t reserved0 : 1;
+ uint8_t a_cable_type : 1;
+ uint8_t usb_lanes : 1;
+ uint8_t usb_32_support : 1;
+ uint8_t usb_20_support : 1;
+ uint8_t usb_20_hub_hop : 2;
+ uint8_t usb_40_support : 1;
+ uint8_t active_elem : 1;
+ uint8_t physical_conn : 1;
+ uint8_t u3_to_u0 : 1;
+ uint8_t u3_power : 3;
+ uint8_t reserved1 : 1;
+ uint8_t shutdown_temp : 8;
+ uint8_t max_operating_temp : 8;
+ };
+ uint32_t raw_value;
+};
+
+/*****************************************************************************/
+/*
+ * Table 6-41 AMA VDO
+ * -------------------------------------------------------------
+ * <31:28> : HW Version
+ * 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version
+ * 0000b..1111b assigned by the VID owner
+ * <23:21> : VDO Version
+ * Version Number of the VDO (not this specification Version):
+ * Version 1.0 = 000b
+ * Values 001b..111b are Reserved and Shall Not be used
+ * <20:8> : Reserved. Shall be set to zero.
+ * <7:5> : VCONN power
+ * When the VCONN required field is set to “Yes” VCONN power
+ * needed by adapter for full functionality
+ * 000b = 1W
+ * 001b = 1.5W
+ * 010b = 2W
+ * 011b = 3W
+ * 100b = 4W
+ * 101b = 5W
+ * 110b = 6W
+ * 111b = Reserved, Shall Not be used
+ * When the VCONN required field is set to “No” Reserved,
+ * Shall be set to zero.
+ * <4> : VCONN required
+ * 0 = No
+ * 1 = Yes
+ * <3> : VBUS required
+ * 0 = No
+ * 1 = Yes
+ * <2:0> : USB Highest Speed
+ * 000b = [USB 2.0] only
+ * 001b = [USB 3.2] Gen1 and USB 2.0
+ * 010b = [USB 3.2] Gen1, Gen2 and USB 2.0
+ * 011b = [USB 2.0] billboard only
+ * 100b..111b = Reserved, Shall Not be used
+ */
+
+/*****************************************************************************/
+/*
+ * Table 6-42 VPD VDO
+ * -------------------------------------------------------------
+ * <31:28> : HW Version
+ * 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version
+ * 0000b..1111b assigned by the VID owner
+ * <23:21> : VDO Version Version Number of the VDO
+ * (not this specification Version):
+ * Version 1.0 = 000b
+ * Values 001b…111b are Reserved and Shall Not be used
+ * <20:17> : Reserved Shall be set to zero.
+ * <16:15> : Maximum VBUS Voltage
+ * Maximum Cable VBUS Voltage:
+ * 00b – 20V
+ * 01b – 30V
+ * 10b – 40V
+ * 11b – 50V
+ * <14> : Charge Through Current Support
+ * Charge Through Support bit=1b:
+ * 0b - 3A capable;
+ * 1b - 5A capable
+ * Charge Through Support bit = 0b: Reserved, Shall be set to zero
+ * <14:13> : Reserved Shall be set to zero.
+ * <12:7> : VBUS Impedance
+ * Charge Through Support bit = 1b:
+ * Vbus impedance through the VPD in 2 mΩ increments.
+ * Values less than 10 mΩ are Reserved and Shall Not be used.
+ * Charge Through Support bit = 0b: Reserved, Shall be set to zero
+ * <6:1> : Ground Impedance
+ * Charge Through Support bit = 1b:
+ * Ground impedance through the VPD in 1 mΩ increments.
+ * Values less than 10 mΩ are Reserved and Shall Not be used.
+ * Charge Through Support bit = 0b: Reserved, Shall be set to zero
+ * <0> : Charge Through Support
+ * 1b – the VPD supports Charge Through
+ * 0b – the VPD does not support Charge Through
+ */
+#define VDO_VPD(hw, fw, vbus, vbusz, gndz, cts) \
+ (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 \
+ | ((vbus) & 0x3) << 15 \
+ | ((vbusz) & 0x3f) << 7 \
+ | ((gndz) & 0x3f) << 1 | (cts))
+
+enum vpd_vbus {
+ VPD_MAX_VBUS_20V,
+ VPD_MAX_VBUS_30V,
+ VPD_MAX_VBUS_40V,
+ VPD_MAX_VBUS_50V,
+};
+
+enum vpd_cts_support {
+ VPD_CTS_SUPPORTED,
+ VPD_CTS_NOT_SUPPORTED,
+};
+
+#define VPD_VDO_MAX_VBUS(vdo) (((vdo) >> 15) & 0x3)
+#define VPD_VDO_VBUS_IMP(vdo) (((vdo) >> 7) & 0x3f)
+#define VPD_VDO_GND_IMP(vdo) (((vdo) >> 1) & 0x3f)
+#define VPD_VDO_CTS(vdo) ((vdo) & 1)
+#define VPD_VBUS_IMP(mo) ((mo + 1) >> 1)
+#define VPD_GND_IMP(mo) (mo)
+
+/*
+ * ############################################################################
+ *
+ * Reference: USB Power Delivery Specification Revision 2.0, Version 1.3
+ *
+ * ############################################################################
+ */
+
+/*****************************************************************************/
+/*
+ * Table 6-28 Passive Cable VDO
+ * -------------------------------------------------------------
+ * <31:28> : HW Version
+ * 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version
+ * 0000b..1111b assigned by the VID owner
+ * <23:20> : Reserved
+ * Shall be set to zero.
+ * <19:18> : USB Type-C plug to USB Type-A/B/C/Captive
+ * 00b = USB Type-A
+ * 01b = USB Type-B
+ * 10b = USB Type-C
+ * 11b = Captive
+ * <17> : Reserved
+ * Shall be set to zero.
+ * <16:13> : Cable Latency
+ * 0000b – Reserved, Shall Not be used
+ * 0001b – <10ns (~1m)
+ * 0010b – 10ns to 20ns (~2m)
+ * 0011b – 20ns to 30ns (~3m)
+ * 0100b – 30ns to 40ns (~4m)
+ * 0101b – 40ns to 50ns (~5m)
+ * 0110b – 50ns to 60ns (~6m)
+ * 0111b – 60ns to 70ns (~7m)
+ * 1000b – > 70ns (>~7m)
+ * 1001b..1111b Reserved, Shall Not be used
+ * Includes latency of electronics in Active Cable
+ * <12:11> : Cable Termination Type
+ * 00b = VCONN not required. Cable Plugs that only support
+ * Discover Identity Commands Shall set these bits to 00b.
+ * 01b = VCONN required
+ * 10b..11b = Reserved, Shall Not be used
+ * <10> : SSTX1 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <9> : SSTX2 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <8> : SSRX1 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <7> : SSRX2 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <6:5> : VBUS Current Handling Capability
+ * 00b = Reserved, Shall Not be used.
+ * 01b = 3A
+ * 10b = 5A
+ * 11b = Reserved, Shall Not be used.
+ * <4> : VBUS through cable
+ * 0 = No
+ * 1 = Yes
+ * <3> : Reserved Shall be set to 0.
+ * <2:0> : USB SuperSpeed Signaling Support
+ * 000b = USB 2.0 only, no SuperSpeed support
+ * 001b = [USB 3.1] Gen1
+ * 010b = [USB 3.1] Gen1 and Gen2
+ * 011b..111b = Reserved, Shall Not be used
+ * See [USB Type-C 1.2] for definitions.
+ */
+enum usb_rev20_ss {
+ USB_R20_SS_U2_ONLY,
+ USB_R20_SS_U31_GEN1,
+ USB_R20_SS_U31_GEN1_GEN2,
+ USB_R20_SS_RES_3,
+ USB_R20_SS_RES_4,
+ USB_R20_SS_RES_5,
+ USB_R20_SS_RES_6,
+ USB_R20_SS_RES_7,
+};
+
+union passive_cable_vdo_rev20 {
+ struct {
+ enum usb_rev20_ss ss: 3;
+ uint8_t reserved0 : 1;
+ uint8_t vbus_cable : 1;
+ enum usb_vbus_cur vbus_cur : 2;
+ uint8_t ssrx2 : 1;
+ uint8_t ssrx1 : 1;
+ uint8_t sstx2 : 1;
+ uint8_t sstx1 : 1;
+ uint8_t termination : 2;
+ uint8_t latency : 4;
+ uint8_t reserved1 : 1;
+ uint8_t connector : 2;
+ uint8_t reserved2 : 4;
+ uint8_t fw_version : 4;
+ uint8_t hw_version : 4;
+ };
+ uint32_t raw_value;
+};
+
+/*****************************************************************************/
+/*
+ * Table 6-29 Active Cable VDO
+ * -------------------------------------------------------------
+ * <31:28> : HW Version
+ * 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version
+ * 0000b..1111b assigned by the VID owner
+ * <23:20> : Reserved
+ * Shall be set to zero.
+ * <19:18> : USB Type-C plug to USB Type-A/B/C/Captive
+ * 00b = USB Type-A
+ * 01b = USB Type-B
+ * 10b = USB Type-C
+ * 11b = Captive
+ * <17> : Reserved
+ * Shall be set to zero.
+ * <16:13> : Cable Latency
+ * 0000b – Reserved, Shall Not be used
+ * 0001b – <10ns (~1m)
+ * 0010b – 10ns to 20ns (~2m)
+ * 0011b – 20ns to 30ns (~3m)
+ * 0100b – 30ns to 40ns (~4m)
+ * 0101b – 40ns to 50ns (~5m)
+ * 0110b – 50ns to 60ns (~6m)
+ * 0111b – 60ns to 70ns (~7m)
+ * 1000b – > 70ns (>~7m)
+ * 1001b..1111b Reserved, Shall Not be used
+ * Includes latency of electronics in Active Cable
+ * <12:11> : Cable Termination Type
+ * 00b..01b = Reserved, Shall Not be used
+ * 10b = One end Active, one end passive, VCONN required
+ * 11b = Both ends Active, VCONN required
+ * <10> : SSTX1 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <9> : SSTX2 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <8> : SSRX1 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <7> : SSRX2 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <6:5> : VBUS Current Handling Capability
+ * 00b = Reserved, Shall Not be used.
+ * 01b = 3A
+ * 10b = 5A
+ * 11b = Reserved, Shall Not be used.
+ * <4> : VBUS through cable
+ * 0 = No
+ * 1 = Yes
+ * <3> : SOP” controller present?
+ * 1 = SOP” controller present
+ * 0 = No SOP” controller present
+ * <2:0> : USB SuperSpeed Signaling Support
+ * 000b = USB 2.0 only, no SuperSpeed support
+ * 001b = [USB 3.1] Gen1
+ * 010b = [USB 3.1] Gen1 and Gen2
+ * 011b..111b = Reserved, Shall Not be used
+ */
+union active_cable_vdo_rev20 {
+ struct {
+ enum usb_rev20_ss ss: 3;
+ uint8_t sop_p_p : 1;
+ uint8_t vbus_cable : 1;
+ enum usb_vbus_cur vbus_cur : 2;
+ uint8_t ssrx2 : 1;
+ uint8_t ssrx1 : 1;
+ uint8_t sstx2 : 1;
+ uint8_t sstx1 : 1;
+ uint8_t termination : 2;
+ uint8_t latency : 4;
+ uint8_t reserved0 : 1;
+ uint8_t connector : 2;
+ uint8_t reserved1 : 1;
+ uint8_t vdo_version : 3;
+ uint8_t fw_version : 4;
+ uint8_t hw_version : 4;
+ };
+ uint32_t raw_value;
+};
+
+/*****************************************************************************/
+/*
+ * Table 6-30 AMA VDO
+ * -------------------------------------------------------------
+ * <31:28> : HW Version
+ * 0000b..1111b assigned by the VID owner
+ * <27:24> : Firmware Version
+ * 0000b..1111b assigned by the VID owner
+ * <23:12> : Reserved
+ * Shall be set to zero.
+ * <11> : SSTX1 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <10> : SSTX2 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <9> : SSRX1 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <8> : SSRX2 Directionality Support
+ * 0 = Fixed
+ * 1 = Configurable
+ * <7:5> : VCONN power
+ * When the VCONN required field is set to “Yes” VCONN power
+ * needed by adapter for full functionality
+ * 000b = 1W
+ * 001b = 1.5W
+ * 010b = 2W
+ * 011b = 3W
+ * 100b = 4W
+ * 101b = 5W
+ * 110b = 6W
+ * 111b = Reserved, Shall Not be used
+ * When the VCONN required field is set to “No” Reserved,
+ * Shall be set to zero.
+ * <4> : VCONN required
+ * 0 = No
+ * 1 = Yes
+ * <3> : VBUS required
+ * 0 = No
+ * 1 = Yes
+ * <2:0> : USB Highest Speed
+ * 000b = [USB 2.0] only
+ * 001b = [USB 3.2] Gen1 and USB 2.0
+ * 010b = [USB 3.2] Gen1, Gen2 and USB 2.0
+ * 011b = [USB 2.0] billboard only
+ * 100b..111b = Reserved, Shall Not be used
+ */
+#define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \
+ (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \
+ | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \
+ | ((vcpwr) & 0x3) << 5 | (vcr) << 4 | (vbr) << 3 \
+ | ((usbss) & 0x7))
+
+#define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
+#define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
+
+enum ama_usb_ss {
+ AMA_USBSS_U2_ONLY,
+ AMA_USBSS_U31_GEN1,
+ AMA_USBSS_U31_GEN2,
+ AMA_USBSS_BBONLY,
+};
+
+#endif /* __CROS_EC_USB_PD_VDO_H */
diff --git a/util/ectool.c b/util/ectool.c
index ac2bd878d5..1d13415399 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -5597,15 +5597,15 @@ int cmd_usb_pd(int argc, char *argv[])
r_v2->control_flags & USB_PD_MUX_TBT_LINK ?
"Uni" : "Bi");
- printf("Cable Speed:");
+ printf("TBT Cable Speed:");
switch (r_v2->cable_speed) {
- case USB3_GEN1:
+ case TBT_SS_U31_GEN1:
printf("TBT Gen1");
break;
- case USB3_GEN1_USB4_GEN2:
+ case TBT_SS_U32_GEN1_GEN2:
printf("TBT Gen1 and TBT Gen2");
break;
- case USB4_GEN3:
+ case TBT_SS_TBT_GEN3:
printf("TBT Gen3");
break;
default: