summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-10-17 07:52:12 -0600
committerCommit Bot <commit-bot@chromium.org>2019-10-24 00:44:34 +0000
commit5f683e3de7f605302ec8af791044cff23b0920ee (patch)
tree13a8448ab03f8ccf31bff8519ecd2dc377854391
parentcb2fa8b437cb14e652f0e6374d3caf8e568a04ac (diff)
downloadchrome-ec-5f683e3de7f605302ec8af791044cff23b0920ee.tar.gz
cleanup: use power and data role enums instead of int
Use first class enums types instead of int for power and data role. BRANCH=none BUG=none TEST=builds and new stack works with single charger on C1 hatch Change-Id: Ied4562e6a148803140cf277bd229b6c3ed801470 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1865985 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--common/usbc/usb_tc_ctvpd_sm.c10
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c20
-rw-r--r--common/usbc/usb_tc_vpd_sm.c10
-rw-r--r--include/usb_tc_sm.h12
-rw-r--r--test/fake_usbc.c13
-rw-r--r--test/usb_prl.c8
6 files changed, 39 insertions, 34 deletions
diff --git a/common/usbc/usb_tc_ctvpd_sm.c b/common/usbc/usb_tc_ctvpd_sm.c
index 7d299e686f..de4bcedf66 100644
--- a/common/usbc/usb_tc_ctvpd_sm.c
+++ b/common/usbc/usb_tc_ctvpd_sm.c
@@ -40,9 +40,9 @@ static struct type_c {
/* state machine context */
struct sm_ctx ctx;
/* current port power role (VPD, SOURCE or SINK) */
- uint8_t power_role;
+ enum pd_power_role power_role;
/* current port data role (DFP or UFP) */
- uint8_t data_role;
+ 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_* */
@@ -141,12 +141,12 @@ static void set_state_tc(const int port, enum usb_tc_state new_state);
/* Public TypeC functions */
-int tc_get_power_role(int port)
+enum pd_power_role tc_get_power_role(int port)
{
return tc[port].power_role;
}
-int tc_get_data_role(int port)
+enum pd_data_role tc_get_data_role(int port)
{
return tc[port].data_role;
}
@@ -162,7 +162,7 @@ uint8_t tc_get_pd_enabled(int port)
return tc[port].pd_enable;
}
-void tc_set_power_role(int port, int role)
+void tc_set_power_role(int port, enum pd_power_role role)
{
tc[port].power_role = role;
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 693a489a0f..569579535d 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -122,9 +122,9 @@ static struct type_c {
/* state machine context */
struct sm_ctx ctx;
/* current port power role (SOURCE or SINK) */
- uint8_t power_role;
+ enum pd_power_role power_role;
/* current port data role (DFP or UFP) */
- uint8_t data_role;
+ enum pd_data_role data_role;
/* Higher-level power deliver state machines are enabled if true. */
uint8_t pd_enable;
#ifdef CONFIG_USB_PE_SM
@@ -668,12 +668,12 @@ void tc_state_init(int port)
restart_tc_sm(port, TC_UNATTACHED_SNK);
}
-int tc_get_power_role(int port)
+enum pd_power_role tc_get_power_role(int port)
{
return tc[port].power_role;
}
-int tc_get_data_role(int port)
+enum pd_data_role tc_get_data_role(int port)
{
return tc[port].data_role;
}
@@ -688,7 +688,7 @@ uint8_t tc_get_pd_enabled(int port)
return tc[port].pd_enable;
}
-void tc_set_power_role(int port, int role)
+void tc_set_power_role(int port, enum pd_power_role role)
{
tc[port].power_role = role;
}
@@ -782,7 +782,7 @@ void tc_event_check(int port, int evt)
* DTS USB-C @ 3 A Rp3A0 RpUSB
*/
-void tc_set_data_role(int port, int role)
+void tc_set_data_role(int port, enum pd_data_role role)
{
tc[port].data_role = role;
@@ -1871,7 +1871,9 @@ static void tc_attached_snk_run(const int port)
TC_CLR_FLAG(port, TC_FLAGS_REQUEST_DR_SWAP);
/* Perform Data Role Swap */
- tc_set_data_role(port, !tc[port].data_role);
+ tc_set_data_role(port,
+ tc[port].data_role == PD_ROLE_UFP ?
+ PD_ROLE_DFP : PD_ROLE_UFP);
}
#ifdef CONFIG_USBC_VCONN
@@ -2302,7 +2304,9 @@ static void tc_attached_src_run(const int port)
TC_CLR_FLAG(port, TC_FLAGS_REQUEST_DR_SWAP);
/* Perform Data Role Swap */
- tc_set_data_role(port, !tc[port].data_role);
+ tc_set_data_role(port,
+ tc[port].data_role == PD_ROLE_DFP ?
+ PD_ROLE_UFP : PD_ROLE_DFP);
}
if (IS_ENABLED(CONFIG_USBC_VCONN)) {
diff --git a/common/usbc/usb_tc_vpd_sm.c b/common/usbc/usb_tc_vpd_sm.c
index 92ce580c53..cb30093be3 100644
--- a/common/usbc/usb_tc_vpd_sm.c
+++ b/common/usbc/usb_tc_vpd_sm.c
@@ -34,9 +34,9 @@ static struct type_c {
/* state machine context */
struct sm_ctx ctx;
/* current port power role (VPD, SOURCE or SINK) */
- uint8_t power_role;
+ enum pd_power_role power_role;
/* current port data role (DFP or UFP) */
- uint8_t data_role;
+ 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_* */
@@ -99,12 +99,12 @@ void tc_state_init(int port)
}
-int tc_get_power_role(int port)
+enum pd_power_role tc_get_power_role(int port)
{
return tc[port].power_role;
}
-int tc_get_data_role(int port)
+enum pd_data_role tc_get_data_role(int port)
{
return tc[port].data_role;
}
@@ -120,7 +120,7 @@ uint8_t tc_get_pd_enabled(int port)
return tc[port].pd_enable;
}
-void tc_set_power_role(int port, int role)
+void tc_set_power_role(int port, enum pd_power_role role)
{
tc[port].power_role = role;
}
diff --git a/include/usb_tc_sm.h b/include/usb_tc_sm.h
index d8a68b08d3..2b9912bc7b 100644
--- a/include/usb_tc_sm.h
+++ b/include/usb_tc_sm.h
@@ -51,17 +51,17 @@ int tc_is_attached_snk(int port);
* Get current data role
*
* @param port USB-C port number
- * @return 0 for ufp, 1 for dfp, 2 for disconnected
+ * @return PD data role
*/
-int tc_get_data_role(int port);
+enum pd_data_role tc_get_data_role(int port);
/**
* Get current power role
*
* @param port USB-C port number
- * @return 0 for sink, 1 for source or vpd
+ * @return PD power role
*/
-int tc_get_power_role(int port);
+enum pd_power_role tc_get_power_role(int port);
/**
* Get current polarity
@@ -86,7 +86,7 @@ uint8_t tc_get_pd_enabled(int port);
* @param port USB-C port number
* @param role power role
*/
-void tc_set_power_role(int port, int role);
+void tc_set_power_role(int port, enum pd_power_role role);
/**
* Set the data role
@@ -94,7 +94,7 @@ void tc_set_power_role(int port, int role);
* @param port USB-C port number
* @param role data role
*/
-void tc_set_data_role(int port, int role);
+void tc_set_data_role(int port, enum pd_data_role role);
/**
* Sets the USB Mux depending on current data role
diff --git a/test/fake_usbc.c b/test/fake_usbc.c
index f9cb69f4c9..9f2d4c12ae 100644
--- a/test/fake_usbc.c
+++ b/test/fake_usbc.c
@@ -6,6 +6,7 @@
*/
#include "common.h"
#include "usb_tc_sm.h"
+#include "usb_pd.h"
int pd_is_vbus_present(int port)
{
@@ -25,22 +26,22 @@ void pd_request_vconn_swap_on(int port)
{}
-static int data_role;
-int tc_get_data_role(int port)
+static enum pd_data_role data_role;
+enum pd_data_role tc_get_data_role(int port)
{
return data_role;
}
-void tc_set_data_role(int port, int role)
+void tc_set_data_role(int port, enum pd_data_role role)
{
data_role = role;
}
-static int power_role;
-int tc_get_power_role(int port)
+static enum pd_power_role power_role;
+enum pd_power_role tc_get_power_role(int port)
{
return power_role;
}
-void tc_set_power_role(int port, int role)
+void tc_set_power_role(int port, enum pd_power_role role)
{
power_role = role;
}
diff --git a/test/usb_prl.c b/test/usb_prl.c
index 308117493b..58bd452e60 100644
--- a/test/usb_prl.c
+++ b/test/usb_prl.c
@@ -95,8 +95,8 @@ static uint32_t test_data[] = {
static struct pd_prl {
int rev;
int pd_enable;
- int power_role;
- int data_role;
+ enum pd_power_role power_role;
+ enum pd_data_role data_role;
int msg_tx_id;
int msg_rx_id;
@@ -723,12 +723,12 @@ static void enable_prl(int port, int en)
prl_set_rev(port, pd_port[port].rev);
}
-int tc_get_power_role(int port)
+enum pd_power_role tc_get_power_role(int port)
{
return pd_port[port].power_role;
}
-int tc_get_data_role(int port)
+enum pd_data_role tc_get_data_role(int port)
{
return pd_port[port].data_role;
}