summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-09-21 09:22:58 -0600
committerCommit Bot <commit-bot@chromium.org>2020-10-05 18:11:27 +0000
commitd4162ed75fc1e1a5d98352ff4b4389224f84db72 (patch)
tree34a1035725e8dbc51919243c144f1c0f0e004e6e
parentf2dbe82834c9bb43e0bd929dea675aa30eab4daf (diff)
downloadchrome-ec-d4162ed75fc1e1a5d98352ff4b4389224f84db72.tar.gz
TCPMv2: Add TYPEC_STATUS command
The TYPEC_STATUS command will be deprecating the informational return from the USB_PD_CONTROL host command. It brings over the enablement, role, and connection information from the older command. Cable specifics are excluded as they are redundant with the discovery return. Information about the mux state is also added for convenience. Additionally, this moves enums and defines which are a part of our overall pd_* API to the ec_commands.h file to ensure consumers have the same field values available for interpretation as the EC. BRANCH=None BUG=b:167700356 TEST=on waddledoo, plug in chargers and dongles and ensure outputs from "ectool typecstatus <port>" match "ectool usbpd <port>" and "ectool usbpdmuxinfo" Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ic7afc0b282b88fdb34cb9a6feef22ad913bb4aae Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2432452 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/usbc/usb_pd_host.c38
-rw-r--r--include/ec_commands.h115
-rw-r--r--include/usb_pd.h26
-rw-r--r--include/usb_pd_tcpm.h25
-rw-r--r--util/ectool.c111
5 files changed, 263 insertions, 52 deletions
diff --git a/common/usbc/usb_pd_host.c b/common/usbc/usb_pd_host.c
index 8fdd8a2748..ff5b540536 100644
--- a/common/usbc/usb_pd_host.c
+++ b/common/usbc/usb_pd_host.c
@@ -10,7 +10,9 @@
#include "console.h"
#include "ec_commands.h"
#include "host_command.h"
+#include "usb_mux.h"
#include "usb_pd.h"
+#include "util.h"
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
@@ -114,3 +116,39 @@ static enum ec_status hc_typec_control(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_TYPEC_CONTROL, hc_typec_control, EC_VER_MASK(0));
+
+static enum ec_status hc_typec_status(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_typec_status *p = args->params;
+ struct ec_response_typec_status *r = args->response;
+ const char *tc_state_name;
+
+ if (p->port >= board_get_usb_pd_port_count())
+ return EC_RES_INVALID_PARAM;
+
+ if (args->response_max < sizeof(*r))
+ return EC_RES_RESPONSE_TOO_BIG;
+
+ args->response_size = sizeof(*r);
+
+ r->pd_enabled = pd_comm_is_enabled(p->port);
+ r->dev_connected = pd_is_connected(p->port);
+ r->sop_connected = pd_capable(p->port);
+
+ r->power_role = pd_get_power_role(p->port);
+ r->data_role = pd_get_data_role(p->port);
+ r->vconn_role = pd_get_vconn_state(p->port) ? PD_ROLE_VCONN_SRC :
+ PD_ROLE_VCONN_OFF;
+ r->polarity = pd_get_polarity(p->port);
+ r->cc_state = pd_get_task_cc_state(p->port);
+ r->dp_pin = get_dp_pin_mode(p->port);
+ r->mux_state = usb_mux_get(p->port);
+
+ tc_state_name = pd_get_task_state_name(p->port);
+ strzcpy(r->tc_state, tc_state_name, sizeof(r->tc_state));
+
+ /* TODO(b/167700356): Add events, revisions, and source cap PDOs */
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_TYPEC_STATUS, hc_typec_status, EC_VER_MASK(0));
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 14b3ab6fd7..11e283b19c 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -5302,7 +5302,13 @@ struct ec_response_host_event_status {
uint32_t status; /* PD MCU host event status */
} __ec_align4;
-/* Set USB type-C port role and muxes */
+/*
+ * Set USB type-C port role and muxes
+ *
+ * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
+ *
+ * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
+ */
#define EC_CMD_USB_PD_CONTROL 0x0101
enum usb_pd_control_role {
@@ -6375,6 +6381,113 @@ struct ec_params_typec_control {
};
} __ec_align1;
+/*
+ * Gather all status information for a port.
+ *
+ * Note: this covers many of the return fields from the deprecated
+ * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
+ * discovery data. The "enum pd_cc_states" is defined with the deprecated
+ * EC_CMD_USB_PD_CONTROL command.
+ *
+ * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
+ *
+ * Version 0 of command is under development
+ * TODO(b/167700356): Remove this statement when version 0 is finalized
+ */
+#define EC_CMD_TYPEC_STATUS 0x0133
+
+/*
+ * Power role.
+ *
+ * Note this is also used for PD header creation, and values align to those in
+ * the Power Delivery Specification Revision 3.0 (See
+ * 6.2.1.1.4 Port Power Role).
+ */
+enum pd_power_role {
+ PD_ROLE_SINK = 0,
+ PD_ROLE_SOURCE = 1
+};
+
+/*
+ * Data role.
+ *
+ * Note this is also used for PD header creation, and the first two values
+ * align to those in the Power Delivery Specification Revision 3.0 (See
+ * 6.2.1.1.6 Port Data Role).
+ */
+enum pd_data_role {
+ PD_ROLE_UFP = 0,
+ PD_ROLE_DFP = 1,
+ PD_ROLE_DISCONNECTED = 2,
+};
+
+enum pd_vconn_role {
+ PD_ROLE_VCONN_OFF = 0,
+ PD_ROLE_VCONN_SRC = 1,
+};
+
+/*
+ * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
+ * regardless of whether a debug accessory is connected.
+ */
+enum tcpc_cc_polarity {
+ /*
+ * _CCx: is used to indicate the polarity while not connected to
+ * a Debug Accessory. Only one CC line will assert a resistor and
+ * the other will be open.
+ */
+ POLARITY_CC1 = 0,
+ POLARITY_CC2 = 1,
+
+ /*
+ * _CCx_DTS is used to indicate the polarity while connected to a
+ * SRC Debug Accessory. Assert resistors on both lines.
+ */
+ POLARITY_CC1_DTS = 2,
+ POLARITY_CC2_DTS = 3,
+
+ /*
+ * The current TCPC code relies on these specific POLARITY values.
+ * Adding in a check to verify if the list grows for any reason
+ * that this will give a hint that other places need to be
+ * adjusted.
+ */
+ POLARITY_COUNT
+};
+
+#define MODE_DP_PIN_A BIT(1)
+#define MODE_DP_PIN_B BIT(2)
+#define MODE_DP_PIN_C BIT(3)
+#define MODE_DP_PIN_D BIT(4)
+#define MODE_DP_PIN_E BIT(5)
+#define MODE_DP_PIN_F BIT(6)
+#define MODE_DP_PIN_ALL GENMASK(6, 0)
+
+struct ec_params_typec_status {
+ uint8_t port;
+} __ec_align1;
+
+struct ec_response_typec_status {
+ uint8_t pd_enabled; /* PD communication enabled - bool */
+ uint8_t dev_connected; /* Device connected - bool */
+ uint8_t sop_connected; /* Device is SOP PD capable - bool */
+ uint8_t reserved1; /* Reserved for future use */
+
+ uint8_t power_role; /* enum pd_power_role */
+ uint8_t data_role; /* enum pd_data_role */
+ uint8_t vconn_role; /* enum pd_vconn_role */
+ uint8_t reserved2; /* Reserved for future use */
+
+ uint8_t polarity; /* enum tcpc_cc_polarity */
+ uint8_t cc_state; /* enum pd_cc_states */
+ uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
+ uint8_t mux_state; /* USB_PD_MUX* - encoded USB mux state */
+
+ char tc_state[32]; /* TC state name */
+
+ /* TODO(b/167700356): Add events, revisions, and source cap PDOs */
+} __ec_align1;
+
/*****************************************************************************/
/* The command range 0x200-0x2FF is reserved for Rotor. */
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 40b24aa79f..c14c2acfbb 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -653,14 +653,6 @@ struct pd_cable {
| ((usb) & 1) << 7 | ((gdr) & 1) << 6 | ((sign) & 0xF) << 2 \
| ((sdir) & 0x3))
-#define MODE_DP_PIN_A 0x01
-#define MODE_DP_PIN_B 0x02
-#define MODE_DP_PIN_C 0x04
-#define MODE_DP_PIN_D 0x08
-#define MODE_DP_PIN_E 0x10
-#define MODE_DP_PIN_F 0x20
-#define MODE_DP_PIN_ALL 0x3f
-
#define MODE_DP_DFP_PIN_SHIFT 8
#define MODE_DP_UFP_PIN_SHIFT 16
@@ -1164,24 +1156,6 @@ enum pd_data_msg_type {
PD_DATA_VENDOR_DEF = 15,
};
-/*
- * Power role. See 6.2.1.1.4 Port Power Role. Only applies to SOP packets.
- * Replaced by pd_cable_plug for SOP' and SOP" packets.
- */
-enum pd_power_role {
- PD_ROLE_SINK = 0,
- PD_ROLE_SOURCE = 1
-};
-
-/*
- * Data role. See 6.2.1.1.6 Port Data Role. Only applies to SOP.
- * Replaced by reserved field for SOP' and SOP" packets.
- */
-enum pd_data_role {
- PD_ROLE_UFP = 0,
- PD_ROLE_DFP = 1,
- PD_ROLE_DISCONNECTED = 2,
-};
/*
* Cable plug. See 6.2.1.1.7 Cable Plug. Only applies to SOP' and SOP".
diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h
index 9044942171..b4cd7654a7 100644
--- a/include/usb_pd_tcpm.h
+++ b/include/usb_pd_tcpm.h
@@ -47,31 +47,6 @@ enum tcpc_rp_value {
TYPEC_RP_RESERVED = 3,
};
-enum tcpc_cc_polarity {
- /*
- * _CCx: is used to indicate the polarity while not connected to
- * a Debug Accessory. Only one CC line will assert a resistor and
- * the other will be open.
- */
- POLARITY_CC1 = 0,
- POLARITY_CC2 = 1,
-
- /*
- * CCx_DTS is used to indicate the polarity while connected to a
- * SRC Debug Accessory. Assert resistors on both lines.
- */
- POLARITY_CC1_DTS = 2,
- POLARITY_CC2_DTS = 3,
-
- /*
- * The current TCPC code relies on these specific POLARITY values.
- * Adding in a check to verify if the list grows for any reason
- * that this will give a hint that other places need to be
- * adjusted.
- */
- POLARITY_COUNT
-};
-
/**
* Returns whether the polarity without the DTS extension
*/
diff --git a/util/ectool.c b/util/ectool.c
index 85be6055bf..822501dc60 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -313,6 +313,8 @@ const char help_str[] =
" Control USB PD policy\n"
" typecdiscovery <port> <type>\n"
" Get discovery information for port and type\n"
+ " typecstatus <port>\n"
+ " Get status information for port\n"
" uptimeinfo\n"
" Get info about how long the EC has been running and the most\n"
" recent AP resets\n"
@@ -9558,6 +9560,114 @@ int cmd_typec_discovery(int argc, char *argv[])
return 0;
}
+int cmd_typec_status(int argc, char *argv[])
+{
+ struct ec_params_typec_status p;
+ struct ec_response_typec_status *r =
+ (struct ec_response_typec_status *)ec_inbuf;
+ char *endptr;
+ int rv;
+ char *desc;
+
+ if (argc < 2) {
+ fprintf(stderr,
+ "Usage: %s <port>\n"
+ " <port> is the type-c port to query\n", argv[0]);
+ return -1;
+ }
+
+ p.port = strtol(argv[1], &endptr, 0);
+ if (endptr && *endptr) {
+ fprintf(stderr, "Bad port\n");
+ return -1;
+ }
+
+ rv = ec_command(EC_CMD_TYPEC_STATUS, 0, &p, sizeof(p),
+ ec_inbuf, ec_max_insize);
+ if (rv < 0)
+ return -1;
+
+ printf("Port C%d: %s, %s State:%s\n"
+ "Role:%s %s%s, Polarity:CC%d\n",
+ p.port,
+ r->pd_enabled ? "enabled" : "disabled",
+ r->dev_connected ? "connected" : "disconnected",
+ r->tc_state,
+ (r->power_role == PD_ROLE_SOURCE) ? "SRC" : "SNK",
+ (r->data_role == PD_ROLE_DFP) ? "DFP" :
+ (r->data_role == PD_ROLE_UFP) ? "UFP" : "",
+ (r->vconn_role == PD_ROLE_VCONN_SRC) ? " VCONN" : "",
+ (r->polarity % 2 + 1));
+
+ switch (r->cc_state) {
+ case PD_CC_NONE:
+ desc = "None";
+ break;
+ case PD_CC_UFP_AUDIO_ACC:
+ desc = "UFP Audio accessory";
+ break;
+ case PD_CC_UFP_DEBUG_ACC:
+ desc = "UFP Debug accessory";
+ break;
+ case PD_CC_UFP_ATTACHED:
+ desc = "UFP attached";
+ break;
+ case PD_CC_DFP_DEBUG_ACC:
+ desc = "DFP Debug accessory";
+ break;
+ case PD_CC_DFP_ATTACHED:
+ desc = "DFP attached";
+ break;
+ default:
+ desc = "UNKNOWN";
+ break;
+ }
+ printf("CC State: %s\n", desc);
+
+ if (r->dp_pin) {
+ switch (r->dp_pin) {
+ case MODE_DP_PIN_A:
+ desc = "A";
+ break;
+ case MODE_DP_PIN_B:
+ desc = "B";
+ break;
+ case MODE_DP_PIN_C:
+ desc = "C";
+ break;
+ case MODE_DP_PIN_D:
+ desc = "D";
+ break;
+ case MODE_DP_PIN_E:
+ desc = "E";
+ break;
+ case MODE_DP_PIN_F:
+ desc = "F";
+ break;
+ default:
+ desc = "UNKNOWN";
+ break;
+ }
+ printf("DP pin mode: %s\n", desc);
+ }
+
+ if (r->mux_state) {
+ printf("MUX: USB=%d DP=%d POLARITY=%s HPD_IRQ=%d HPD_LVL=%d\n"
+ " SAFE=%d TBT=%d USB4=%d\n",
+ !!(r->mux_state & USB_PD_MUX_USB_ENABLED),
+ !!(r->mux_state & USB_PD_MUX_DP_ENABLED),
+ (r->mux_state & USB_PD_MUX_POLARITY_INVERTED) ?
+ "INVERTED" : "NORMAL",
+ !!(r->mux_state & USB_PD_MUX_HPD_IRQ),
+ !!(r->mux_state & USB_PD_MUX_HPD_LVL),
+ !!(r->mux_state & USB_PD_MUX_SAFE_MODE),
+ !!(r->mux_state & USB_PD_MUX_TBT_COMPAT_ENABLED),
+ !!(r->mux_state & USB_PD_MUX_USB4_ENABLED));
+ }
+
+ return 0;
+}
+
int cmd_tp_self_test(int argc, char* argv[])
{
int rv;
@@ -10020,6 +10130,7 @@ const struct command commands[] = {
{"tmp006raw", cmd_tmp006raw},
{"typeccontrol", cmd_typec_control},
{"typecdiscovery", cmd_typec_discovery},
+ {"typecstatus", cmd_typec_status},
{"uptimeinfo", cmd_uptimeinfo},
{"usbchargemode", cmd_usb_charge_set_mode},
{"usbmux", cmd_usb_mux},