diff options
author | Ayushee <ayushee.shah@intel.com> | 2020-05-08 03:09:41 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-09 19:28:05 +0000 |
commit | 6b90174eb1dd461ed336aa88b9f35a73767d0dd6 (patch) | |
tree | 197c98c87d8c524d3a33daae81395b1b8ef69267 /common/usb_pd_protocol.c | |
parent | 94492ef4046034935a1f8c6ac0887f2453c70151 (diff) | |
download | chrome-ec-6b90174eb1dd461ed336aa88b9f35a73767d0dd6.tar.gz |
usb_pd: Cleanup: Cable flags
Instead of using CABLE_FLAGS_SOP_PRIME_ENABLE and
CABLE_FLAGS_SOP_PRIME_PRIME_ENABLE cable flags, add the type of message
to be transmitted directly in the message header.
BUG=b:148528713
BRANCH=none
TEST=1. make buildall -j
2. Able to enter DP mode with Type-C dock and Type-C to DP
connector.
3. Able to enter Thunderbolt-Compatible mode with thunderbolt dock
with both Active and Passive cables.
4. Able to Enter USB4 mode with USB4 device with thunderbolt Gen2
cable.
Change-Id: Ib0cac818200e7ab8f73cace85ffee65203019709
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2159592
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r-- | common/usb_pd_protocol.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index a82c2b79d0..526769a8e2 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -257,6 +257,8 @@ static struct pd_protocol { timestamp_t vdm_timeout; /* next Vendor Defined Message to send */ uint32_t vdo_data[VDO_MAX_SIZE]; + /* type of transmit message (SOP/SOP'/SOP'') */ + enum tcpm_transmit_type xmit_type; uint8_t vdo_count; /* VDO to retry if UFP responder replied busy. */ uint32_t vdo_retry; @@ -641,17 +643,18 @@ static bool consume_sop_repeat_message(int port, uint8_t msg_id) * using SOP* Packets Shall maintain copies of the last MessageID for * each type of SOP* it uses. */ -static bool consume_repeat_message(int port, uint16_t msg_header) +static bool consume_repeat_message(int port, uint32_t msg_header) { uint8_t msg_id = PD_HEADER_ID(msg_header); + enum tcpm_transmit_type sop = PD_HEADER_GET_SOP(msg_header); /* If repeat message ignore, except softreset control request. */ if (PD_HEADER_TYPE(msg_header) == PD_CTRL_SOFT_RESET && PD_HEADER_CNT(msg_header) == 0) { return false; - } else if (is_transmit_msg_sop_prime(port)) { + } else if (sop == TCPC_TX_SOP_PRIME) { return consume_sop_prime_repeat_msg(port, msg_id); - } else if (is_transmit_msg_sop_prime_prime(port)) { + } else if (sop == TCPC_TX_SOP_PRIME_PRIME) { return consume_sop_prime_prime_repeat_msg(port, msg_id); } else { return consume_sop_repeat_message(port, msg_id); @@ -1212,20 +1215,23 @@ static int send_bist_cmd(int port) #endif static void queue_vdm(int port, uint32_t *header, const uint32_t *data, - int data_cnt) + int data_cnt, enum tcpm_transmit_type type) { pd[port].vdo_count = data_cnt + 1; pd[port].vdo_data[0] = header[0]; - memcpy(&pd[port].vdo_data[1], data, sizeof(uint32_t) * data_cnt); + pd[port].xmit_type = type; + memcpy(&pd[port].vdo_data[1], data, + sizeof(uint32_t) * data_cnt); /* Set ready, pd task will actually send */ pd[port].vdm_state = VDM_STATE_READY; } static void handle_vdm_request(int port, int cnt, uint32_t *payload, - uint16_t head) + uint32_t head) { int rlen = 0; uint32_t *rdata; + enum tcpm_transmit_type rtype = TCPC_TX_SOP; if (pd[port].vdm_state == VDM_STATE_BUSY) { /* If UFP responded busy retry after timeout */ @@ -1248,14 +1254,15 @@ 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, head); + rlen = pd_svdm(port, cnt, payload, &rdata, head, &rtype); else rlen = pd_custom_vdm(port, cnt, payload, &rdata); if (rlen > 0) { - queue_vdm(port, rdata, &rdata[1], rlen - 1); + queue_vdm(port, rdata, &rdata[1], rlen - 1, rtype); return; } + if (debug_level >= 2) CPRINTF("C%d Unhandled VDM VID %04x CMD %04x\n", port, PD_VDO_VID(payload[0]), payload[0] & 0xFFFF); @@ -1503,7 +1510,7 @@ static void pd_update_pdo_flags(int port, uint32_t pdo) #endif } -static void handle_data_request(int port, uint16_t head, +static void handle_data_request(int port, uint32_t head, uint32_t *payload) { int type = PD_HEADER_TYPE(head); @@ -1672,7 +1679,7 @@ static void pd_dr_swap(int port) pd[port].flags |= PD_FLAGS_CHECK_IDENTITY; } -static void handle_ctrl_request(int port, uint16_t head, +static void handle_ctrl_request(int port, uint32_t head, uint32_t *payload) { int type = PD_HEADER_TYPE(head); @@ -1990,7 +1997,7 @@ static void handle_ext_request(int port, uint16_t head, uint32_t *payload) } #endif -static void handle_request(int port, uint16_t head, +static void handle_request(int port, uint32_t head, uint32_t *payload) { int cnt = PD_HEADER_CNT(head); @@ -2069,7 +2076,7 @@ void pd_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data, #ifdef CONFIG_USB_PD_REV30 pd[port].vdo_data[0] |= VDO_SVDM_VERS(vdo_ver[pd[port].rev]); #endif - queue_vdm(port, pd[port].vdo_data, data, count); + queue_vdm(port, pd[port].vdo_data, data, count, TCPC_TX_SOP); task_wake(PD_PORT_TO_TASK_ID(port)); } @@ -2149,7 +2156,7 @@ static void pd_vdm_send_state_machine(int port) { int res; uint16_t header; - enum pd_msg_type msg_type = pd_msg_tx_type(port); + enum tcpm_transmit_type msg_type = pd[port].xmit_type; switch (pd[port].vdm_state) { case VDM_STATE_READY: @@ -2177,8 +2184,8 @@ static void pd_vdm_send_state_machine(int port) * data role swap takes place during source and sink * negotiation and in case of failure, a soft reset is issued. */ - if ((msg_type == PD_MSG_SOP_PRIME) || - (msg_type == PD_MSG_SOP_PRIME_PRIME)) { + if ((msg_type == TCPC_TX_SOP_PRIME) || + (msg_type == TCPC_TX_SOP_PRIME_PRIME)) { /* Prepare SOP'/SOP'' header and send VDM */ header = PD_HEADER( PD_DATA_VENDOR_DEF, @@ -2188,13 +2195,8 @@ static void pd_vdm_send_state_machine(int port) (int)pd[port].vdo_count, pd_get_rev(port), 0); - res = pd_transmit(port, - (msg_type == PD_MSG_SOP_PRIME) ? - TCPC_TX_SOP_PRIME : - TCPC_TX_SOP_PRIME_PRIME, - header, - pd[port].vdo_data, - AMS_START); + res = pd_transmit(port, msg_type, header, + pd[port].vdo_data, AMS_START); /* * In the case of SOP', if there is no response from * the cable, it's a non-emark cable and therefore the @@ -2217,10 +2219,10 @@ static void pd_vdm_send_state_machine(int port) (int)pd[port].vdo_count, pd_get_rev(port), 0); - if ((msg_type == PD_MSG_SOP_PRIME_PRIME) && + if ((msg_type == TCPC_TX_SOP_PRIME_PRIME) && IS_ENABLED(CONFIG_USBC_SS_MUX)) { exit_tbt_mode_sop_prime(port); - } else if (msg_type == PD_MSG_SOP_PRIME) { + } else if (msg_type == TCPC_TX_SOP_PRIME) { pd[port].vdo_data[0] = VDO(USB_SID_PD, 1, CMD_DISCOVER_SVID); } @@ -2856,7 +2858,7 @@ static void pd_send_enter_usb(int port, int *timeout) void pd_task(void *u) { - int head; + uint32_t head; int port = TASK_ID_TO_PD_PORT(task_get_current()); uint32_t payload[7]; int timeout = 10*MSEC; |