summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-10-17 09:33:31 -0600
committerCommit Bot <commit-bot@chromium.org>2019-10-24 18:01:17 +0000
commite248f208ab8a55667bfe60ce48a188fc1a4620cc (patch)
tree2b3955afb2a53432c09467998e930407a47f02c1 /common
parent39f7d5d0e5c3ae72b9837a676fac401dfe51e745 (diff)
downloadchrome-ec-e248f208ab8a55667bfe60ce48a188fc1a4620cc.tar.gz
cleanup: clean up reference to power role vs cable plug
The PD header specifies the power role for SOP packets and cable plug for SOP' and SOP" packets. Refactor code to make this more obvious. BRANCH=none BUG=none TEST=builds and new stack runs on hatch Change-Id: I6cdb1561082d2142214ac65703ff42586b16d70b Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1865986 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/usb_pd_protocol.c12
-rw-r--r--common/usbc/usb_prl_sm.c13
-rw-r--r--common/usbc/usb_tc_ctvpd_sm.c25
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c9
-rw-r--r--common/usbc/usb_tc_vpd_sm.c26
5 files changed, 50 insertions, 35 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 266c83788b..1ce06d9260 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -2212,10 +2212,14 @@ static void pd_vdm_send_state_machine(int port)
if (is_sop_prime_ready(port, pd[port].data_role,
pd[port].flags)) {
/* Prepare SOP'/SOP'' header and send VDM */
- header = PD_HEADER(PD_DATA_VENDOR_DEF, PD_PLUG_DFP_UFP,
- 0, pd[port].msg_id,
- (int)pd[port].vdo_count,
- pd_get_rev(port), 0);
+ header = PD_HEADER(
+ PD_DATA_VENDOR_DEF,
+ PD_PLUG_FROM_DFP_UFP,
+ 0,
+ pd[port].msg_id,
+ (int)pd[port].vdo_count,
+ pd_get_rev(port),
+ 0);
res = pd_transmit(port, TCPC_TX_SOP_PRIME, header,
pd[port].vdo_data);
/*
diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c
index 1c4761e5f4..e95f2a3c9e 100644
--- a/common/usbc/usb_prl_sm.c
+++ b/common/usbc/usb_prl_sm.c
@@ -612,13 +612,18 @@ static void prl_tx_layer_reset_for_transmit_run(const int port)
static uint32_t get_sop_star_header(const int port)
{
+ const int is_sop_packet = pdmsg[port].xmit_type == TCPC_TX_SOP;
+
+ /* SOP vs SOP'/SOP" headers are different. Replace fields as needed */
return PD_HEADER(
pdmsg[port].msg_type,
- tc_get_power_role(port),
- tc_get_data_role(port),
+ is_sop_packet ?
+ tc_get_power_role(port) : tc_get_cable_plug(port),
+ is_sop_packet ?
+ tc_get_data_role(port) : 0,
prl_tx[port].msg_id_counter[pdmsg[port].xmit_type],
pdmsg[port].data_objs,
- (pdmsg[port].xmit_type == TCPC_TX_SOP) ?
+ is_sop_packet ?
pdmsg[port].rev : pdmsg[port].cable_rev,
pdmsg[port].ext);
}
@@ -1518,7 +1523,7 @@ static void prl_rx_wait_for_phy_message(const int port, int evt)
if (!IS_ENABLED(CONFIG_USB_TYPEC_CTVPD) &&
!IS_ENABLED(CONFIG_USB_TYPEC_VPD) &&
PD_HEADER_GET_SOP(header) != PD_MSG_SOP &&
- PD_HEADER_PROLE(header) == PD_PLUG_DFP_UFP)
+ PD_HEADER_PROLE(header) == PD_PLUG_FROM_DFP_UFP)
return;
if (cnt == 0 && type == PD_CTRL_SOFT_RESET) {
diff --git a/common/usbc/usb_tc_ctvpd_sm.c b/common/usbc/usb_tc_ctvpd_sm.c
index de4bcedf66..c935be380f 100644
--- a/common/usbc/usb_tc_ctvpd_sm.c
+++ b/common/usbc/usb_tc_ctvpd_sm.c
@@ -39,10 +39,6 @@
static struct type_c {
/* state machine context */
struct sm_ctx ctx;
- /* current port power role (VPD, SOURCE or SINK) */
- enum pd_power_role power_role;
- /* current port data role (DFP or UFP) */
- enum pd_data_role data_role;
/* Higher-level power deliver state machines are enabled if true. */
uint8_t pd_enable;
/* port flags, see TC_FLAGS_* */
@@ -143,14 +139,24 @@ static void set_state_tc(const int port, enum usb_tc_state new_state);
enum pd_power_role tc_get_power_role(int port)
{
- return tc[port].power_role;
+ /* Vconn power device is always the sink */
+ return PD_ROLE_SINK;
+}
+
+enum pd_cable_plug tc_get_cable_plug(int port)
+{
+ /* Vconn power device is always the cable */
+ return PD_PLUG_FROM_CABLE;
}
enum pd_data_role tc_get_data_role(int port)
{
- return tc[port].data_role;
+ /* Vconn power device doesn't have a data role, but UFP matches SNK */
+ return PD_ROLE_UFP;
}
+/* Note tc_set_power_role and tc_set_data_role are unimplemented */
+
uint8_t tc_get_polarity(int port)
{
/* Does not track polarity */
@@ -162,11 +168,6 @@ uint8_t tc_get_pd_enabled(int port)
return tc[port].pd_enable;
}
-void tc_set_power_role(int port, enum pd_power_role role)
-{
- tc[port].power_role = role;
-}
-
void tc_reset_support_timer(int port)
{
tc[port].support_timer_reset |= SUPPORT_TIMER_RESET_REQUEST;
@@ -185,8 +186,6 @@ void tc_state_init(int port)
/* Disable pd state machines */
tc[port].pd_enable = 0;
- tc[port].power_role = PD_PLUG_CABLE_VPD;
- tc[port].data_role = 0; /* Reserved for VPD */
tc[port].billboard_presented = 0;
tc[port].flags = 0;
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 569579535d..286fa3a660 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -678,6 +678,15 @@ enum pd_data_role tc_get_data_role(int port)
return tc[port].data_role;
}
+enum pd_cable_plug tc_get_cable_plug(int port)
+{
+ /*
+ * Messages sent by this state machine are always from a DFP/UFP,
+ * i.e. the chromebook.
+ */
+ return PD_PLUG_FROM_DFP_UFP;
+}
+
uint8_t tc_get_polarity(int port)
{
return tc[port].polarity;
diff --git a/common/usbc/usb_tc_vpd_sm.c b/common/usbc/usb_tc_vpd_sm.c
index cb30093be3..dedba97513 100644
--- a/common/usbc/usb_tc_vpd_sm.c
+++ b/common/usbc/usb_tc_vpd_sm.c
@@ -33,10 +33,6 @@
static struct type_c {
/* state machine context */
struct sm_ctx ctx;
- /* current port power role (VPD, SOURCE or SINK) */
- enum pd_power_role power_role;
- /* current port data role (DFP or UFP) */
- enum pd_data_role data_role;
/* Higher-level power deliver state machines are enabled if true. */
uint8_t pd_enable;
/* port flags, see TC_FLAGS_* */
@@ -93,22 +89,29 @@ void tc_state_init(int port)
/* Disable pd state machines */
tc[port].pd_enable = 0;
- tc[port].power_role = PD_PLUG_CABLE_VPD;
- tc[port].data_role = 0; /* Reserved for VPD */
tc[port].flags = 0;
}
-
enum pd_power_role tc_get_power_role(int port)
{
- return tc[port].power_role;
+ /* Vconn power device is always the sink */
+ return PD_ROLE_SINK;
+}
+
+enum pd_cable_plug tc_get_cable_plug(int port)
+{
+ /* Vconn power device is always the cable */
+ return PD_PLUG_FROM_CABLE;
}
enum pd_data_role tc_get_data_role(int port)
{
- return tc[port].data_role;
+ /* Vconn power device doesn't have a data role, but UFP match SNK */
+ return PD_ROLE_UFP;
}
+/* Note tc_set_power_role and tc_set_data_role are unimplemented */
+
uint8_t tc_get_polarity(int port)
{
/* Does not track polarity yet */
@@ -120,11 +123,6 @@ uint8_t tc_get_pd_enabled(int port)
return tc[port].pd_enable;
}
-void tc_set_power_role(int port, enum pd_power_role role)
-{
- tc[port].power_role = role;
-}
-
void tc_event_check(int port, int evt)
{
/* Do Nothing */