summaryrefslogtreecommitdiff
path: root/common/usbc/usb_pd_host.c
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 /common/usbc/usb_pd_host.c
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>
Diffstat (limited to 'common/usbc/usb_pd_host.c')
-rw-r--r--common/usbc/usb_pd_host.c38
1 files changed, 38 insertions, 0 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));