From 08a39ff9dbb8a1e6417ed3b55eb35cc9850d5057 Mon Sep 17 00:00:00 2001 From: Andrew McRae Date: Tue, 16 Jun 2020 09:00:16 +1000 Subject: TCPMv2: Fix the sending of CMD_EXIT_MODE Fix the request to send CMD_EXIT_MODE, which needs to set the right state in order for the message to be sent. Also handle the receipt of an ACK for CMD_EXIT_MODE. BUG=b:158813138 TEST=Confirm that DP mode is exited. BRANCH=none Signed-off-by: Andrew McRae Change-Id: Id9b58616771e729d8ae6543f973669be7649dc45 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2245584 Reviewed-by: Andrew McRae Tested-by: Andrew McRae Commit-Queue: Andrew McRae --- common/usbc/dp_alt_mode.c | 8 ++++++++ common/usbc/usb_pe_drp_sm.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/common/usbc/dp_alt_mode.c b/common/usbc/dp_alt_mode.c index ff8909bbd6..f8ccc5f3c8 100644 --- a/common/usbc/dp_alt_mode.c +++ b/common/usbc/dp_alt_mode.c @@ -61,6 +61,14 @@ void dp_vdm_acked(int port, enum tcpm_transmit_type type, int vdo_count, pd_get_amode_data(port, type, USB_SID_DISPLAYPORT); const uint8_t vdm_cmd = PD_VDO_CMD(vdm[0]); + /* + * Handle the ACK of a request to exit alt mode. + */ + if (type == TCPC_TX_SOP && vdm_cmd == CMD_EXIT_MODE) { + dpm_init(port); + return; + } + if (type != TCPC_TX_SOP || next_vdm_cmd[port] != vdm_cmd) { print_unexpected_response(port, type, CMDT_RSP_ACK, vdm_cmd); dpm_set_mode_entry_done(port); diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index dadcfe02af..45e2ed4206 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -1152,7 +1152,9 @@ static bool common_src_snk_dpm_requests(int port) /* * Init VDM CMD_EXIT_MODE message. * alt_opos must be set with the opos to be sent. + * TODO: Convert this to use DPM_REQUEST_VDM. */ + pe[port].tx_type = TCPC_TX_SOP; pe[port].vdm_data[0] = VDO( USB_SID_DISPLAYPORT, 1, /* structured */ @@ -1162,6 +1164,8 @@ static bool common_src_snk_dpm_requests(int port) VDO_CMDT(CMDT_INIT) | CMD_EXIT_MODE); pe[port].vdm_cnt = 1; + set_state_pe(port, PE_VDM_REQUEST); + return true; } else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_VDM)) { PE_CLR_DPM_REQUEST(port, DPM_REQUEST_VDM); @@ -4911,7 +4915,7 @@ static void pe_vdm_response_entry(int port) rx_payload[0] &= ~VDO_CMDT_MASK; if (cmd_type != CMDT_INIT) { - CPRINTF("ERR:CMDT:%d\n", vdo_cmd); + CPRINTF("ERR:CMDT:%d:%d\n", cmd_type, vdo_cmd); if (pe[port].power_role == PD_ROLE_SOURCE) set_state_pe(port, PE_SRC_READY); -- cgit v1.2.1