summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2020-01-08 06:54:30 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-09 19:24:10 +0000
commitd3a1820df21b12842232ab88a5c1a0490640bb25 (patch)
treeb0855ad62d8c5f42178cec6cf9038563c9253fb1
parenta6591e9d5c7caa04f94e604d8a649d9f8e6d5b5b (diff)
downloadchrome-ec-d3a1820df21b12842232ab88a5c1a0490640bb25.tar.gz
pd: cleanup pd_get_role
pd_get_role in the TCPMv1 stack meant pd_get_power_role. pd_get_role in the TCPMv2 stack meant pd_get_data_role. This CL will clean that up and make them the correct naming. pd_get_power_role will also return an enum pd_power_role type instead of an int. BUG=b:147290482 BRANCH=none TEST=make buildall -j Change-Id: I73ee465401ccd050c2bd151f2fc043a59d95e079 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1991844 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--baseboard/kalista/usb_pd_policy.c4
-rw-r--r--board/chell/usb_pd_policy.c4
-rw-r--r--board/coffeecake/usb_pd_policy.c6
-rw-r--r--board/dingdong/usb_pd_policy.c4
-rw-r--r--board/hoho/usb_pd_policy.c4
-rw-r--r--board/host/usb_pd_policy.c4
-rw-r--r--board/pdeval-stm32f072/usb_pd_policy.c4
-rw-r--r--board/plankton/usb_pd_policy.c4
-rw-r--r--board/servo_v4/usb_pd_policy.c4
-rw-r--r--board/twinkie/usb_pd_policy.c4
-rw-r--r--board/zinger/usb_pd_policy.c4
-rw-r--r--chip/host/usb_pd_phy.c2
-rw-r--r--chip/stm32/usb_pd_phy.c2
-rw-r--r--common/charge_manager.c2
-rw-r--r--common/usb_common.c5
-rw-r--r--common/usb_pd_protocol.c6
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c15
-rw-r--r--driver/tcpm/fusb302.c2
-rw-r--r--include/usb_pd.h8
-rw-r--r--test/charge_manager.c32
-rw-r--r--test/fake_usbc.c2
21 files changed, 74 insertions, 48 deletions
diff --git a/baseboard/kalista/usb_pd_policy.c b/baseboard/kalista/usb_pd_policy.c
index 8d9a10e883..89af4b50fb 100644
--- a/baseboard/kalista/usb_pd_policy.c
+++ b/baseboard/kalista/usb_pd_policy.c
@@ -66,6 +66,8 @@ int pd_snk_is_vbus_provided(int port)
return !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L);
}
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/chell/usb_pd_policy.c b/board/chell/usb_pd_policy.c
index b2e8de464f..6367b3bf38 100644
--- a/board/chell/usb_pd_policy.c
+++ b/board/chell/usb_pd_policy.c
@@ -110,7 +110,9 @@ void pd_execute_data_swap(int port, int data_role)
/* Do nothing */
}
-void pd_check_pr_role(int port, int pr_role, int flags)
+void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
/*
* If partner is dual-role power and dualrole toggling is on, consider
diff --git a/board/coffeecake/usb_pd_policy.c b/board/coffeecake/usb_pd_policy.c
index 89f6bd28ad..f263ca11ab 100644
--- a/board/coffeecake/usb_pd_policy.c
+++ b/board/coffeecake/usb_pd_policy.c
@@ -134,9 +134,11 @@ void pd_execute_data_swap(int port, int data_role)
/* TODO: turn on pp5000, pp3300 */
}
-void pd_check_pr_role(int port, int pr_role, int flags)
+void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
- if (pr_role == PD_ROLE_UFP && !gpio_get_level(GPIO_AC_PRESENT_L))
+ if (pr_role == PD_ROLE_SINK && !gpio_get_level(GPIO_AC_PRESENT_L))
pd_request_power_swap(port);
}
diff --git a/board/dingdong/usb_pd_policy.c b/board/dingdong/usb_pd_policy.c
index 5f90775f2a..9d2ddd4471 100644
--- a/board/dingdong/usb_pd_policy.c
+++ b/board/dingdong/usb_pd_policy.c
@@ -91,7 +91,9 @@ void pd_execute_data_swap(int port, int data_role)
/* Do nothing */
}
-void pd_check_pr_role(int port, int pr_role, int flags)
+void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/hoho/usb_pd_policy.c b/board/hoho/usb_pd_policy.c
index eac1da8435..a1bca1add0 100644
--- a/board/hoho/usb_pd_policy.c
+++ b/board/hoho/usb_pd_policy.c
@@ -68,7 +68,9 @@ __override int pd_check_data_swap(int port, int data_role)
return 0;
}
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/host/usb_pd_policy.c b/board/host/usb_pd_policy.c
index 56a01d6a3b..a8b884e8cc 100644
--- a/board/host/usb_pd_policy.c
+++ b/board/host/usb_pd_policy.c
@@ -61,7 +61,9 @@ __override int pd_check_data_swap(int port, int data_role)
return 1;
}
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/pdeval-stm32f072/usb_pd_policy.c b/board/pdeval-stm32f072/usb_pd_policy.c
index 27cf027b48..59f30d424a 100644
--- a/board/pdeval-stm32f072/usb_pd_policy.c
+++ b/board/pdeval-stm32f072/usb_pd_policy.c
@@ -153,7 +153,9 @@ int pd_check_vconn_swap(int port)
}
#endif
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/plankton/usb_pd_policy.c b/board/plankton/usb_pd_policy.c
index 64e2ec8493..f538586eea 100644
--- a/board/plankton/usb_pd_policy.c
+++ b/board/plankton/usb_pd_policy.c
@@ -125,7 +125,9 @@ __override int pd_check_data_swap(int port, int data_role)
return 1;
}
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c
index 61b6b51314..862d2d9fdc 100644
--- a/board/servo_v4/usb_pd_policy.c
+++ b/board/servo_v4/usb_pd_policy.c
@@ -729,7 +729,9 @@ __override void pd_execute_data_swap(int port, int data_role)
*/
}
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
/*
* Don't define any policy to initiate power role swap.
diff --git a/board/twinkie/usb_pd_policy.c b/board/twinkie/usb_pd_policy.c
index 253bf717f4..0e044db840 100644
--- a/board/twinkie/usb_pd_policy.c
+++ b/board/twinkie/usb_pd_policy.c
@@ -71,7 +71,9 @@ __override int pd_check_data_swap(int port, int data_role)
return 1;
}
-__override void pd_check_pr_role(int port, int pr_role, int flags)
+__override void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index 560a8ba3b6..162037fd57 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -284,7 +284,9 @@ void pd_execute_data_swap(int port, int data_role)
/* Do nothing */
}
-void pd_check_pr_role(int port, int pr_role, int flags)
+void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags)
{
}
diff --git a/chip/host/usb_pd_phy.c b/chip/host/usb_pd_phy.c
index 347035a6d0..ba81b986ad 100644
--- a/chip/host/usb_pd_phy.c
+++ b/chip/host/usb_pd_phy.c
@@ -358,7 +358,7 @@ void pd_hw_release(int port)
pd_phy[port].hw_init_done = 0;
}
-void pd_hw_init(int port, int role)
+void pd_hw_init(int port, enum pd_power_role role)
{
pd_config_init(port, role);
pd_phy[port].hw_init_done = 1;
diff --git a/chip/stm32/usb_pd_phy.c b/chip/stm32/usb_pd_phy.c
index 426cac15d3..4e845882d9 100644
--- a/chip/stm32/usb_pd_phy.c
+++ b/chip/stm32/usb_pd_phy.c
@@ -611,7 +611,7 @@ void pd_hw_init_rx(int port)
task_enable_irq(IRQ_COMP);
}
-void pd_hw_init(int port, int role)
+void pd_hw_init(int port, enum pd_power_role role)
{
struct pd_physical *phy = &pd_phy[port];
uint32_t val;
diff --git a/common/charge_manager.c b/common/charge_manager.c
index 7f50e50b68..f9c6d8060c 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -149,7 +149,7 @@ static int is_sink(int port)
if (!is_pd_port(port))
return board_charge_port_is_sink(port);
- return pd_get_role(port) == PD_ROLE_SINK;
+ return pd_get_power_role(port) == PD_ROLE_SINK;
}
/**
diff --git a/common/usb_common.c b/common/usb_common.c
index 946f5ffbdd..39b2060714 100644
--- a/common/usb_common.c
+++ b/common/usb_common.c
@@ -553,13 +553,14 @@ __overridable int pd_check_power_swap(int port)
*/
if (pd_get_dual_role(port) == PD_DRP_TOGGLE_ON)
return 1;
- else if (pd_get_role(port) == PD_ROLE_SOURCE)
+ else if (pd_get_power_role(port) == PD_ROLE_SOURCE)
return 1;
return 0;
}
-__overridable void pd_check_pr_role(int port, int pr_role, int flags)
+__overridable void pd_check_pr_role(int port,
+ enum pd_power_role pr_role, int flags)
{
/*
* If partner is dual-role power and dualrole toggling is on, consider
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 77b61b363b..a854850da2 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -169,7 +169,7 @@ static volatile task_id_t sysjump_task_waiting = TASK_ID_INVALID;
static struct pd_protocol {
/* 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;
/* 3-bit rolling message ID counter */
@@ -1809,7 +1809,7 @@ void pd_request_data_swap(int port)
task_wake(PD_PORT_TO_TASK_ID(port));
}
-static void pd_set_power_role(int port, int role)
+static void pd_set_power_role(int port, enum pd_power_role role)
{
pd[port].power_role = role;
#ifdef CONFIG_USB_PD_DUAL_ROLE
@@ -2569,7 +2569,7 @@ static void pd_update_dual_role_config(int port)
}
}
-int pd_get_role(int port)
+enum pd_power_role pd_get_power_role(int port)
{
return pd[port].power_role;
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index cd89ea51fd..4af6d7ed45 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -659,11 +659,16 @@ enum tcpc_cc_polarity pd_get_polarity(int port)
return tc[port].polarity;
}
-int pd_get_role(int port)
+enum pd_data_role pd_get_data_role(int port)
{
return tc[port].data_role;
}
+enum pd_power_role pd_get_power_role(int port)
+{
+ return tc[port].power_role;
+}
+
int pd_is_vbus_present(int port)
{
if (IS_ENABLED(CONFIG_USB_PD_VBUS_DETECT_TCPC))
@@ -720,12 +725,8 @@ static __maybe_unused void bc12_role_change_handler(int port)
int event;
int task_id = USB_CHG_PORT_TO_TASK_ID(port);
- /*
- * TODO(b/147290482) Cleanup pd_get_role to return enum
- * pd_power_role type.
- */
- /* Get the power of our device (not the port partner) */
- switch (pd_get_role(port)) {
+ /* Get the data role of our device */
+ switch (pd_get_data_role(port)) {
case PD_ROLE_UFP:
event = USB_CHG_EVENT_DR_UFP;
break;
diff --git a/driver/tcpm/fusb302.c b/driver/tcpm/fusb302.c
index 3514b2e865..dc31228506 100644
--- a/driver/tcpm/fusb302.c
+++ b/driver/tcpm/fusb302.c
@@ -1078,7 +1078,7 @@ static int fusb302_tcpm_enter_low_power_mode(int port)
mode = TCPC_REG_CONTROL2_MODE_UFP;
break;
case PD_DRP_FREEZE:
- mode = pd_get_role(port) == PD_ROLE_SINK ?
+ mode = pd_get_power_role(port) == PD_ROLE_SINK ?
TCPC_REG_CONTROL2_MODE_UFP :
TCPC_REG_CONTROL2_MODE_DFP;
break;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 74cd8f27c7..87e24e2ba5 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1294,7 +1294,7 @@ void pd_set_dual_role(int port, enum pd_dual_role_states state);
*
* @param port Port number from which to get role
*/
-int pd_get_role(int port);
+enum pd_power_role pd_get_power_role(int port);
/* Control Message type */
enum pd_ctrl_msg_type {
@@ -1783,7 +1783,9 @@ int pd_check_vconn_swap(int port);
* @param pr_role Our power role
* @param flags PD flags
*/
-__override_proto void pd_check_pr_role(int port, int pr_role, int flags);
+__override_proto void pd_check_pr_role(int port,
+ enum pd_power_role pr_role,
+ int flags);
/**
* Check current data role for potential data swap
@@ -2255,7 +2257,7 @@ void pd_hw_release(int port);
* @param port USB-C port number
* @param role Role to initialize pins in
*/
-void pd_hw_init(int port, int role);
+void pd_hw_init(int port, enum pd_power_role role);
/**
* Initialize the reception side of hardware used for PD.
diff --git a/test/charge_manager.c b/test/charge_manager.c
index 9ac87aa11d..08d640cbb0 100644
--- a/test/charge_manager.c
+++ b/test/charge_manager.c
@@ -36,7 +36,7 @@ static unsigned int active_charge_limit = CHARGE_SUPPLIER_NONE;
static unsigned int active_charge_port = CHARGE_PORT_NONE;
static unsigned int charge_port_to_reject = CHARGE_PORT_NONE;
static int new_power_request[CONFIG_USB_PD_PORT_MAX_COUNT];
-static int power_role[CONFIG_USB_PD_PORT_MAX_COUNT];
+static enum pd_power_role power_role[CONFIG_USB_PD_PORT_MAX_COUNT];
/* Callback functions called by CM on state change */
void board_set_charge_limit(int port, int supplier, int charge_ma,
@@ -82,7 +82,7 @@ static void pd_set_role(int port, int role)
power_role[port] = role;
}
-int pd_get_role(int port)
+enum pd_power_role pd_get_power_role(int port)
{
return power_role[port];
}
@@ -465,7 +465,7 @@ static int test_override(void)
charge_manager_update_dualrole(0, CAP_DUALROLE);
charge_manager_set_override(OVERRIDE_DONT_CHARGE);
wait_for_charge_manager_refresh();
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
/*
* Verify that an override request to a dual-role source port
@@ -478,14 +478,14 @@ static int test_override(void)
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == 0);
TEST_ASSERT(active_charge_limit == 200);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SINK);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SINK);
/* Set override to "don't charge", then verify we're not charging */
charge_manager_set_override(OVERRIDE_DONT_CHARGE);
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
TEST_ASSERT(active_charge_limit == 0);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
/* Update a charge supplier, verify that we still aren't charging */
charge.current = 200;
@@ -493,14 +493,14 @@ static int test_override(void)
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
TEST_ASSERT(active_charge_limit == 0);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
/* Turn override off, verify that we go back to the correct charge */
charge_manager_set_override(OVERRIDE_OFF);
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == 1);
TEST_ASSERT(active_charge_limit == 500);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
return EC_SUCCESS;
}
@@ -533,7 +533,7 @@ static int test_dual_role(void)
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == 0);
TEST_ASSERT(active_charge_limit == 500);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SINK);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SINK);
/* Remove override and verify we go back to previous state */
charge_manager_set_override(OVERRIDE_OFF);
@@ -544,7 +544,7 @@ static int test_dual_role(void)
#else
TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
TEST_ASSERT(active_charge_limit == 0);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
#endif
/* Mark P0 as the override port, verify that we again charge. */
@@ -554,7 +554,7 @@ static int test_dual_role(void)
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == 0);
TEST_ASSERT(active_charge_limit == 550);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SINK);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SINK);
/*
* Insert a dual-role charger into P1 and set the override. Verify
@@ -567,8 +567,8 @@ static int test_dual_role(void)
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == 1);
TEST_ASSERT(active_charge_limit == 500);
- TEST_ASSERT(pd_get_role(1) == PD_ROLE_SINK);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(1) == PD_ROLE_SINK);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
/* Set override back to P0 and verify switch */
charge_manager_set_override(0);
@@ -577,8 +577,8 @@ static int test_dual_role(void)
wait_for_charge_manager_refresh();
TEST_ASSERT(active_charge_port == 0);
TEST_ASSERT(active_charge_limit == 600);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SINK);
- TEST_ASSERT(pd_get_role(1) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SINK);
+ TEST_ASSERT(pd_get_power_role(1) == PD_ROLE_SOURCE);
/* Insert a dedicated charger and verify override is removed */
charge.current = 0;
@@ -594,7 +594,7 @@ static int test_dual_role(void)
#else
TEST_ASSERT(active_charge_port == 1);
TEST_ASSERT(active_charge_limit == 400);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
#endif
/*
@@ -633,7 +633,7 @@ static int test_dual_role(void)
*/
TEST_ASSERT(active_charge_port == 1);
TEST_ASSERT(active_charge_limit == 200);
- TEST_ASSERT(pd_get_role(0) == PD_ROLE_SOURCE);
+ TEST_ASSERT(pd_get_power_role(0) == PD_ROLE_SOURCE);
#endif
return EC_SUCCESS;
diff --git a/test/fake_usbc.c b/test/fake_usbc.c
index aab7f0a7ed..ef32e60d91 100644
--- a/test/fake_usbc.c
+++ b/test/fake_usbc.c
@@ -132,7 +132,7 @@ enum pd_dual_role_states pd_get_dual_role(int port)
return PD_DRP_TOGGLE_ON;
}
-__overridable int pd_get_role(int port)
+__overridable enum pd_power_role pd_get_power_role(int port)
{
return PD_ROLE_SINK;
}