summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2022-10-20 11:47:18 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-28 23:17:34 +0000
commit1e0abfa71e84e6f870d986088e7ce4fb7ead8395 (patch)
tree0b47213c24e8629c190f72fb770cfd0637e101a6
parentdf6a10d22b520a3c89e29e533f147d513df1611c (diff)
downloadchrome-ec-1e0abfa71e84e6f870d986088e7ce4fb7ead8395.tar.gz
TCPMv2: Add host command to send VDM REQ messages
Add an option for the AP to send us VDM REQ messages to pass on to the port partner or cable. This is the first of a series of commits, and later ones will add the transmission of replies to the AP as well as the underlying EC actions that still need to take place (ex. storing active modes and such). LOW_COVERAGE_REASON=Zoss incorrectly marks variable declarations as uncovered BRANCH=None BUG=b:208884535 TEST=./twister -T ./zephyr/test, load on Skyrim and verify messages are sent as directed to partner and cable with TotalPhase Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I205eaa73e7b4b7aa64c1168ef1d8505f1781a1cd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3969859 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--common/usbc/usb_pd_host.c30
-rw-r--r--include/ec_commands.h15
-rw-r--r--include/usb_pd.h1
-rw-r--r--util/ectool.cc34
4 files changed, 78 insertions, 2 deletions
diff --git a/common/usbc/usb_pd_host.c b/common/usbc/usb_pd_host.c
index 1e2965d114..502abc374a 100644
--- a/common/usbc/usb_pd_host.c
+++ b/common/usbc/usb_pd_host.c
@@ -112,6 +112,8 @@ static enum ec_status hc_typec_control(struct host_cmd_handler_args *args)
{
const struct ec_params_typec_control *p = args->params;
mux_state_t mode;
+ uint32_t data[VDO_MAX_SIZE];
+ enum tcpci_msg_type tx_type;
if (p->port >= board_get_usb_pd_port_count())
return EC_RES_INVALID_PARAM;
@@ -140,6 +142,34 @@ static enum ec_status hc_typec_control(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
case TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE:
return pd_set_bist_share_mode(p->bist_share_mode);
+ case TYPEC_CONTROL_COMMAND_SEND_VDM_REQ:
+ if (!IS_ENABLED(CONFIG_USB_PD_VDM_AP_CONTROL))
+ return EC_RES_INVALID_PARAM;
+
+ if (p->vdm_req_params.vdm_data_objects <= 0 ||
+ p->vdm_req_params.vdm_data_objects > VDO_MAX_SIZE)
+ return EC_RES_INVALID_PARAM;
+
+ memcpy(data, p->vdm_req_params.vdm_data,
+ sizeof(uint32_t) * p->vdm_req_params.vdm_data_objects);
+
+ switch (p->vdm_req_params.partner_type) {
+ case TYPEC_PARTNER_SOP:
+ tx_type = TCPCI_MSG_SOP;
+ break;
+ case TYPEC_PARTNER_SOP_PRIME:
+ tx_type = TCPCI_MSG_SOP_PRIME;
+ break;
+ case TYPEC_PARTNER_SOP_PRIME_PRIME:
+ tx_type = TCPCI_MSG_SOP_PRIME_PRIME;
+ break;
+ default:
+ return EC_RES_INVALID_PARAM;
+ }
+
+ return pd_request_vdm(p->port, data,
+ p->vdm_req_params.vdm_data_objects,
+ tx_type);
default:
return EC_RES_INVALID_PARAM;
}
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 892787e4dc..c6f89cd172 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -6716,6 +6716,7 @@ struct ec_response_regulator_get_voltage {
enum typec_partner_type {
TYPEC_PARTNER_SOP = 0,
TYPEC_PARTNER_SOP_PRIME = 1,
+ TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
};
struct ec_params_typec_discovery {
@@ -6747,6 +6748,7 @@ enum typec_control_command {
TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
TYPEC_CONTROL_COMMAND_USB_MUX_SET,
TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
+ TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
};
/* Modes (USB or alternate) that a type-C port may enter. */
@@ -6772,6 +6774,17 @@ struct typec_usb_mux_set {
uint8_t mux_flags;
} __ec_align1;
+#define VDO_MAX_SIZE 7
+
+struct typec_vdm_req {
+ /* VDM data, including VDM header */
+ uint32_t vdm_data[VDO_MAX_SIZE];
+ /* Number of 32-bit fields filled in */
+ uint8_t vdm_data_objects;
+ /* Partner to address - see enum typec_partner_type */
+ uint8_t partner_type;
+} __ec_align1;
+
struct ec_params_typec_control {
uint8_t port;
uint8_t command; /* enum typec_control_command */
@@ -6793,6 +6806,8 @@ struct ec_params_typec_control {
struct typec_usb_mux_set mux_params;
/* Used for BIST_SHARE_MODE */
uint8_t bist_share_mode;
+ /* Used for VMD_REQ */
+ struct typec_vdm_req vdm_req_params;
uint8_t placeholder[128];
};
} __ec_align1;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 92580252a5..bf385c19c2 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -476,7 +476,6 @@ struct partner_active_modes {
* VDM object is minimum of VDM header + 6 additional data objects.
*/
#define VDO_HDR_SIZE 1
-#define VDO_MAX_SIZE 7
#define VDM_VER10 0
#define VDM_VER20 1
diff --git a/util/ectool.cc b/util/ectool.cc
index 61c0e85301..0b3ee18791 100644
--- a/util/ectool.cc
+++ b/util/ectool.cc
@@ -10149,7 +10149,10 @@ int cmd_typec_control(int argc, char *argv[])
" <mux_mode> is one of: dp, dock, usb, tbt,\n"
" usb4, none, safe\n"
" 5: Enable bist share mode\n"
- " args: <0: DISABLE, 1: ENABLE>\n",
+ " args: <0: DISABLE, 1: ENABLE>\n"
+ " 6: Send VDM REQ\n"
+ " args: <tx_type vdm_hdr [vdo...]>\n"
+ " <tx_type> is 0 - SOP, 1 - SOP', 2 - SOP''\n",
argv[0]);
return -1;
}
@@ -10253,6 +10256,35 @@ int cmd_typec_control(int argc, char *argv[])
}
p.bist_share_mode = conversion_result;
break;
+ case TYPEC_CONTROL_COMMAND_SEND_VDM_REQ:
+ if (argc < 5) {
+ fprintf(stderr, "Missing VDM header and type\n");
+ return -1;
+ }
+ if (argc > 4 + VDO_MAX_SIZE) {
+ fprintf(stderr, "Too many VDOs\n");
+ return -1;
+ }
+
+ conversion_result = strtol(argv[3], &endptr, 0);
+ if ((endptr && *endptr) || conversion_result > UINT8_MAX ||
+ conversion_result < 0) {
+ fprintf(stderr, "Bad SOP* type\n");
+ return -1;
+ }
+ p.vdm_req_params.partner_type = conversion_result;
+
+ int vdm_index;
+ for (vdm_index = 0; vdm_index < argc - 4; vdm_index++) {
+ uint32_t vdm_entry =
+ strtoul(argv[vdm_index + 4], &endptr, 0);
+ if (endptr && *endptr) {
+ fprintf(stderr, "Bad VDO\n");
+ return -1;
+ }
+ p.vdm_req_params.vdm_data[vdm_index] = vdm_entry;
+ }
+ p.vdm_req_params.vdm_data_objects = vdm_index;
}
rv = ec_command(EC_CMD_TYPEC_CONTROL, 0, &p, sizeof(p), ec_inbuf,