usb_pd: Move cable communication functions to common file

BUG=b:148528713
BRANCH=none
TEST=Verified on TCPMV1 and TCPMv2, able to get correct
     cable characteristics.

Change-Id: I812b21c87661952bf4e86acaa194d4b136371594
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2051628
Reviewed-by: Diana Z <dzigterman@chromium.org>
Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
This commit is contained in:
Ayushee 2020-02-07 15:13:51 -08:00 committed by Commit Bot
parent 7bffc114e8
commit d4bc8b52d0
6 changed files with 81 additions and 51 deletions

View File

@ -437,6 +437,53 @@ void usb_mux_set_safe_mode(int port)
ppc_set_sbu(port, 0);
}
bool is_vdo_present(int cnt, int index)
{
return cnt > index;
}
/*
* ############################################################################
*
* Cable communication functions
*
* ############################################################################
*/
enum idh_ptype get_usb_pd_cable_type(int port)
{
struct pd_cable *cable = pd_get_cable_attributes(port);
return cable->type;
}
void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
uint16_t head)
{
struct pd_cable *cable = pd_get_cable_attributes(port);
/* Get cable rev */
cable->rev = PD_HEADER_REV(head);
if (is_vdo_present(cnt, VDO_INDEX_IDH)) {
cable->type = PD_IDH_PTYPE(payload[VDO_INDEX_IDH]);
if (is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE1))
cable->attr.raw_value =
payload[VDO_INDEX_PTYPE_CABLE1];
/*
* Ref USB PD Spec 3.0 Pg 145. For active cable there are two
* VDOs. Hence storing the second VDO.
*/
if (is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE2))
cable->attr2.raw_value =
payload[VDO_INDEX_PTYPE_CABLE2];
cable->is_identified = 1;
cable->discovery = PD_DISC_COMPLETE;
}
}
__overridable void svdm_safe_dp_mode(int port)
{
/* make DP interface safe until configure */

View File

@ -173,11 +173,6 @@ void reset_pd_cable(int port)
cable[port].last_sop_p_p_msg_id = INVALID_MSG_ID_COUNTER;
}
enum idh_ptype get_usb_pd_cable_type(int port)
{
return cable[port].type;
}
union tbt_mode_resp_cable get_cable_tbt_vdo(int port)
{
/*
@ -294,11 +289,6 @@ void disable_enter_usb4_mode(int port)
static struct pd_policy pe[CONFIG_USB_PD_PORT_MAX_COUNT];
static int is_vdo_present(int cnt, int index)
{
return cnt > index;
}
static void enable_transmit_sop_prime(int port)
{
if (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP))
@ -545,33 +535,6 @@ void pd_dfp_pe_init(int port)
memset(&pe[port], 0, sizeof(struct pd_policy));
}
static void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
uint16_t head)
{
if (cable[port].is_identified)
return;
/* Get cable rev */
cable[port].rev = PD_HEADER_REV(head);
if (is_vdo_present(cnt, VDO_INDEX_IDH)) {
cable[port].type = PD_IDH_PTYPE(payload[VDO_INDEX_IDH]);
if (is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE1))
cable[port].attr.raw_value =
payload[VDO_INDEX_PTYPE_CABLE1];
}
/*
* Ref USB PD Spec 3.0 Pg 145. For active cable there are two VDOs.
* Hence storing the second VDO.
*/
if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE2) &&
cable[port].type == IDH_PTYPE_ACABLE)
cable[port].attr2.raw_value = payload[VDO_INDEX_PTYPE_CABLE2];
cable[port].is_identified = 1;
}
static int dfp_discover_ident(uint32_t *payload)
{
payload[0] = VDO(USB_SID_PD, 1, CMD_DISCOVER_IDENT);

View File

@ -4001,15 +4001,8 @@ static void pe_vdm_identity_request_cbl_run(int port)
* PE_SRC_VDM_Identity_ACKed and
* PE_INIT_PORT_VDM_Identity_ACKed embedded here
*/
pe[port].cable.rev =
PD_HEADER_REV(rx_emsg[port].header);
pe[port].cable.type = PD_IDH_PTYPE(payload[1]);
pe[port].cable.attr.raw_value = payload[3];
if (cnt > 4)
pe[port].cable.attr2.raw_value =
payload[4];
pe[port].cable.discovery = PD_DISC_COMPLETE;
pe[port].cable.is_identified = 1;
dfp_consume_cable_response(port, cnt, payload,
rx_emsg[port].header);
/*
* Note: If port partner runs PD 2.0, we must
@ -4245,11 +4238,6 @@ static void pe_vdm_request_exit(int port)
PE_CLR_FLAG(port, PE_FLAGS_INTERRUPTIBLE_AMS);
}
enum idh_ptype get_usb_pd_cable_type(int port)
{
return pe[port].cable.type;
}
/**
* PE_VDM_Acked
*/

View File

@ -19,3 +19,8 @@ int pd_check_vconn_swap(int port)
{
return 1;
}
void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
uint16_t head)
{
}

View File

@ -1849,6 +1849,17 @@ enum pd_msg_type pd_msg_tx_type(int port, enum pd_data_role data_role,
*/
void reset_pd_cable(int port);
/**
* Returns true if the number of data objects in the payload is greater than
* than the VDO index
*
* @param cnt number of data objects in payload
* @param index VDO Index
* @return True if number of data objects is greater than VDO index,
* false otherwise
*/
bool is_vdo_present(int cnt, int index);
/**
* Return the type of cable attached
*
@ -1857,6 +1868,17 @@ void reset_pd_cable(int port);
*/
enum idh_ptype get_usb_pd_cable_type(int port);
/**
* Stores the cable's response to discover Identity SOP' request
*
* @param port USB-C port number
* @param cnt number of data objects in payload
* @param payload payload data
* @param head PD packet header
*/
void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
uint16_t head);
/**
* Return enter USB message payload
*

View File

@ -192,6 +192,11 @@ bool pd_is_disconnected(int port)
#endif /* !CONFIG_USB_DRP_ACC_TRYSRC && !CONFIG_USB_CTVPD */
#ifndef CONFIG_USB_DRP_ACC_TRYSRC
void dfp_consume_cable_response(int port, int cnt, uint32_t *payload,
uint16_t head)
{
}
void pd_set_dual_role(int port, enum pd_dual_role_states state)
{
}