summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2020-09-16 12:41:15 -0600
committerCommit Bot <commit-bot@chromium.org>2020-09-21 22:03:07 +0000
commitcb4a02d5e0358631242ada9178bbc6d5b8367340 (patch)
tree7fc8dae92bdc09f0453086aa39d10e932e34e49f
parent3e5d154aaa0c8e71953e1227ffd760f61efe8135 (diff)
downloadchrome-ec-cb4a02d5e0358631242ada9178bbc6d5b8367340.tar.gz
TCPMv2: Move DPM requests to public API
It is safe (atomic bit ops) and will soon be necessary (new host commands) to send DPM requests from outside the PD tasks. Rename pe_dpm_request to pd_dpm_request and move the declarations into usb_pd.h to reflect this. BUG=b:168030639 TEST=make buildall BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: Ied43e9f6973a3172b98090cc068a607257dce21b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2415068 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--common/usbc/usb_pd_console.c16
-rw-r--r--common/usbc/usb_pd_dpm.c7
-rw-r--r--common/usbc/usb_pe_drp_sm.c8
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c14
-rw-r--r--include/usb_pd.h38
-rw-r--r--include/usb_pe_sm.h37
-rw-r--r--test/usb_pd_console.c4
-rw-r--r--test/usb_pe_drp_old.c2
8 files changed, 63 insertions, 63 deletions
diff --git a/common/usbc/usb_pd_console.c b/common/usbc/usb_pd_console.c
index 1e892a585d..e183f0852b 100644
--- a/common/usbc/usb_pd_console.c
+++ b/common/usbc/usb_pd_console.c
@@ -70,9 +70,9 @@ test_export_static int command_pd(int argc, char **argv)
if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE)) {
if (!strcasecmp(argv[2], "tx")) {
- pe_dpm_request(port, DPM_REQUEST_SNK_STARTUP);
+ pd_dpm_request(port, DPM_REQUEST_SNK_STARTUP);
} else if (!strcasecmp(argv[2], "charger")) {
- pe_dpm_request(port, DPM_REQUEST_SRC_STARTUP);
+ pd_dpm_request(port, DPM_REQUEST_SRC_STARTUP);
} else if (!strcasecmp(argv[2], "dev")) {
int max_volt;
@@ -84,7 +84,7 @@ test_export_static int command_pd(int argc, char **argv)
max_volt = pd_get_max_voltage();
}
pd_request_source_voltage(port, max_volt);
- pe_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
+ pd_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
ccprintf("max req: %dmV\n", max_volt);
} else if (!strcasecmp(argv[2], "disable")) {
pd_comm_enable(port, 0);
@@ -95,20 +95,20 @@ test_export_static int command_pd(int argc, char **argv)
ccprintf("Port C%d enabled\n", port);
return EC_SUCCESS;
} else if (!strcasecmp(argv[2], "hard")) {
- pe_dpm_request(port, DPM_REQUEST_HARD_RESET_SEND);
+ pd_dpm_request(port, DPM_REQUEST_HARD_RESET_SEND);
} else if (!strcasecmp(argv[2], "soft")) {
- pe_dpm_request(port, DPM_REQUEST_SOFT_RESET_SEND);
+ pd_dpm_request(port, DPM_REQUEST_SOFT_RESET_SEND);
} else if (!strcasecmp(argv[2], "swap")) {
if (argc < 4)
return EC_ERROR_PARAM_COUNT;
if (!strcasecmp(argv[3], "power"))
- pe_dpm_request(port, DPM_REQUEST_PR_SWAP);
+ pd_dpm_request(port, DPM_REQUEST_PR_SWAP);
else if (!strcasecmp(argv[3], "data"))
- pe_dpm_request(port, DPM_REQUEST_DR_SWAP);
+ pd_dpm_request(port, DPM_REQUEST_DR_SWAP);
else if (IS_ENABLED(CONFIG_USBC_VCONN_SWAP) &&
!strcasecmp(argv[3], "vconn"))
- pe_dpm_request(port, DPM_REQUEST_VCONN_SWAP);
+ pd_dpm_request(port, DPM_REQUEST_VCONN_SWAP);
else
return EC_ERROR_PARAM3;
} else if (!strcasecmp(argv[2], "dualrole")) {
diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c
index 54ccdad536..d1a26ee54b 100644
--- a/common/usbc/usb_pd_dpm.c
+++ b/common/usbc/usb_pd_dpm.c
@@ -15,7 +15,6 @@
#include "usb_mode.h"
#include "usb_pd.h"
#include "usb_pd_dpm.h"
-#include "usb_pe_sm.h"
#include "usb_tbt_alt_mode.h"
#include "tcpm.h"
@@ -125,7 +124,7 @@ static void dpm_attempt_mode_entry(int port)
/* Check if the device and cable support USB4. */
if (IS_ENABLED(CONFIG_USB_PD_USB4) && enter_usb_is_capable(port)) {
- pe_dpm_request(port, DPM_REQUEST_ENTER_USB);
+ pd_dpm_request(port, DPM_REQUEST_ENTER_USB);
return;
}
@@ -166,7 +165,7 @@ static void dpm_attempt_mode_entry(int port)
return;
}
- pe_dpm_request(port, DPM_REQUEST_VDM);
+ pd_dpm_request(port, DPM_REQUEST_VDM);
}
static void dpm_attempt_mode_exit(int port)
@@ -203,7 +202,7 @@ static void dpm_attempt_mode_exit(int port)
return;
}
- pe_dpm_request(port, DPM_REQUEST_VDM);
+ pd_dpm_request(port, DPM_REQUEST_VDM);
}
}
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 47341a2b82..a238d522bf 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -1166,7 +1166,7 @@ void pe_got_soft_reset(int port)
set_state_pe(port, PE_SOFT_RESET);
}
-void pe_dpm_request(int port, enum pe_dpm_request req)
+void pd_dpm_request(int port, enum pd_dpm_request req)
{
PE_SET_DPM_REQUEST(port, req);
}
@@ -1449,7 +1449,7 @@ void pd_request_power_swap(int port)
* requested by policy.
*/
pe[port].src_snk_pr_swap_counter = 0;
- pe_dpm_request(port, DPM_REQUEST_PR_SWAP);
+ pd_dpm_request(port, DPM_REQUEST_PR_SWAP);
}
int pd_is_port_partner_dualrole(int port)
@@ -2117,7 +2117,7 @@ static void pe_src_transition_supply_run(int port)
* PR_Swap
*/
if (pd_get_src_cap_cnt(port) == 0)
- pe_dpm_request(port, DPM_REQUEST_GET_SRC_CAPS);
+ pd_dpm_request(port, DPM_REQUEST_GET_SRC_CAPS);
set_state_pe(port, PE_SRC_READY);
} else {
@@ -2809,7 +2809,7 @@ static void pe_snk_select_capability_run(int port)
* request Sink Capabilities for possible FRS
*/
if (IS_ENABLED(CONFIG_USB_PD_FRS))
- pe_dpm_request(port,
+ pd_dpm_request(port,
DPM_REQUEST_GET_SNK_CAPS);
return;
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index ba550672c8..c2a3e196e8 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -512,7 +512,7 @@ void pd_update_contract(int port)
{
if (IS_ENABLED(CONFIG_USB_PE_SM)) {
if (IS_ATTACHED_SRC(port))
- pe_dpm_request(port, DPM_REQUEST_SRC_CAP_CHANGE);
+ pd_dpm_request(port, DPM_REQUEST_SRC_CAP_CHANGE);
}
}
@@ -522,9 +522,9 @@ void pd_request_source_voltage(int port, int mv)
pd_set_max_voltage(mv);
if (IS_ATTACHED_SNK(port))
- pe_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
+ pd_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
else
- pe_dpm_request(port, DPM_REQUEST_PR_SWAP);
+ pd_dpm_request(port, DPM_REQUEST_PR_SWAP);
task_wake(PD_PORT_TO_TASK_ID(port));
}
@@ -537,7 +537,7 @@ void pd_set_external_voltage_limit(int port, int mv)
/* Must be in Attached.SNK when this function is called */
if (get_state_tc(port) == TC_ATTACHED_SNK)
- pe_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
+ pd_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
task_wake(PD_PORT_TO_TASK_ID(port));
}
@@ -548,7 +548,7 @@ void pd_set_new_power_request(int port)
if (IS_ENABLED(CONFIG_USB_PE_SM)) {
/* Must be in Attached.SNK when this function is called */
if (get_state_tc(port) == TC_ATTACHED_SNK)
- pe_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
+ pd_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL);
}
}
@@ -1696,7 +1696,7 @@ void pd_request_vconn_swap_on(int port)
void pd_request_vconn_swap(int port)
{
- pe_dpm_request(port, DPM_REQUEST_VCONN_SWAP);
+ pd_dpm_request(port, DPM_REQUEST_VCONN_SWAP);
}
#endif
@@ -3486,7 +3486,7 @@ static void pd_chipset_startup(void)
* is an existing connection.
*/
if (IS_ENABLED(CONFIG_USB_PE_SM))
- pe_dpm_request(i, DPM_REQUEST_PORT_DISCOVERY);
+ pd_dpm_request(i, DPM_REQUEST_PORT_DISCOVERY);
}
CPRINTS("PD:S5->S3");
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 806df4d396..4d8a98bac9 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -940,6 +940,34 @@ enum pd_dual_role_states {
/* Switch to source */
PD_DRP_FORCE_SOURCE,
};
+
+/*
+ * Device Policy Manager Requests.
+ * NOTE: These are usually set by host commands from the AP.
+ */
+enum pd_dpm_request {
+ DPM_REQUEST_DR_SWAP = BIT(0),
+ DPM_REQUEST_PR_SWAP = BIT(1),
+ DPM_REQUEST_VCONN_SWAP = BIT(2),
+ DPM_REQUEST_GOTO_MIN = BIT(3),
+ DPM_REQUEST_SRC_CAP_CHANGE = BIT(4),
+ DPM_REQUEST_GET_SNK_CAPS = BIT(5),
+ DPM_REQUEST_SEND_PING = BIT(6),
+ DPM_REQUEST_SOURCE_CAP = BIT(7),
+ DPM_REQUEST_NEW_POWER_LEVEL = BIT(8),
+ DPM_REQUEST_VDM = BIT(9),
+ DPM_REQUEST_BIST_RX = BIT(10),
+ DPM_REQUEST_BIST_TX = BIT(11),
+ DPM_REQUEST_SNK_STARTUP = BIT(12),
+ DPM_REQUEST_SRC_STARTUP = BIT(13),
+ DPM_REQUEST_HARD_RESET_SEND = BIT(14),
+ DPM_REQUEST_SOFT_RESET_SEND = BIT(15),
+ DPM_REQUEST_PORT_DISCOVERY = BIT(16),
+ DPM_REQUEST_SEND_ALERT = BIT(17),
+ DPM_REQUEST_ENTER_USB = BIT(18),
+ DPM_REQUEST_GET_SRC_CAPS = BIT(19),
+};
+
/**
* Get dual role state
*
@@ -2236,6 +2264,16 @@ void pd_log_recv_vdm(int port, int cnt, uint32_t *payload);
void pd_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data,
int count);
+/**
+ * Instruct the Policy Engine to perform a Device Policy Manager Request
+ * This function is called from the Device Policy Manager and only has effect
+ * if the current Policy Engine state is Src.Ready or Snk.Ready.
+ *
+ * @param port USB-C port number
+ * @param req Device Policy Manager Request
+ */
+void pd_dpm_request(int port, enum pd_dpm_request req);
+
/*
* TODO(b/155890173): Probably, this should only be used by the DPM, and
* pd_send_vdm should be implemented in terms of DPM functions.
diff --git a/include/usb_pe_sm.h b/include/usb_pe_sm.h
index 340c0b486b..0cd3bd86da 100644
--- a/include/usb_pe_sm.h
+++ b/include/usb_pe_sm.h
@@ -19,33 +19,6 @@ enum pe_error {
ERR_TCH_XMIT,
};
-/*
- * Device Policy Manager Requests.
- * NOTE: These are usually set by host commands from the AP.
- */
-enum pe_dpm_request {
- DPM_REQUEST_DR_SWAP = BIT(0),
- DPM_REQUEST_PR_SWAP = BIT(1),
- DPM_REQUEST_VCONN_SWAP = BIT(2),
- DPM_REQUEST_GOTO_MIN = BIT(3),
- DPM_REQUEST_SRC_CAP_CHANGE = BIT(4),
- DPM_REQUEST_GET_SNK_CAPS = BIT(5),
- DPM_REQUEST_SEND_PING = BIT(6),
- DPM_REQUEST_SOURCE_CAP = BIT(7),
- DPM_REQUEST_NEW_POWER_LEVEL = BIT(8),
- DPM_REQUEST_VDM = BIT(9),
- DPM_REQUEST_BIST_RX = BIT(10),
- DPM_REQUEST_BIST_TX = BIT(11),
- DPM_REQUEST_SNK_STARTUP = BIT(12),
- DPM_REQUEST_SRC_STARTUP = BIT(13),
- DPM_REQUEST_HARD_RESET_SEND = BIT(14),
- DPM_REQUEST_SOFT_RESET_SEND = BIT(15),
- DPM_REQUEST_PORT_DISCOVERY = BIT(16),
- DPM_REQUEST_SEND_ALERT = BIT(17),
- DPM_REQUEST_ENTER_USB = BIT(18),
- DPM_REQUEST_GET_SRC_CAPS = BIT(19),
-};
-
/**
* Runs the Policy Engine State Machine
*
@@ -151,16 +124,6 @@ void pe_vconn_swap_complete(int port);
*/
int pe_is_explicit_contract(int port);
-/**
- * Instruct the Policy Engine to perform a Device Policy Manager Request
- * This function is called from the Device Policy Manager and only has effect
- * if the current Policy Engine state is Src.Ready or Snk.Ready.
- *
- * @param port USB-C port number
- * @param req Device Policy Manager Request
- */
-void pe_dpm_request(int port, enum pe_dpm_request req);
-
/*
* Return true if port partner is dualrole capable
*
diff --git a/test/usb_pd_console.c b/test/usb_pd_console.c
index e7649e3d32..800eae7b3d 100644
--- a/test/usb_pd_console.c
+++ b/test/usb_pd_console.c
@@ -23,7 +23,7 @@ int remote_flashing(int argc, char **argv);
static enum try_src_override_t try_src_override;
static int test_port;
-static enum pe_dpm_request request;
+static enum pd_dpm_request request;
static int max_volt;
static int comm_enable;
static int dev_info;
@@ -52,7 +52,7 @@ void pe_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data,
vdm_data[i] = data[i];
}
-void pe_dpm_request(int port, enum pe_dpm_request req)
+void pd_dpm_request(int port, enum pd_dpm_request req)
{
test_port = port;
request = req;
diff --git a/test/usb_pe_drp_old.c b/test/usb_pe_drp_old.c
index 3098f75bae..c9815b4726 100644
--- a/test/usb_pe_drp_old.c
+++ b/test/usb_pe_drp_old.c
@@ -327,7 +327,7 @@ test_static int test_prl_is_busy(enum pd_power_role pr)
prl_is_busy_flag = true;
/* Make a request to perform a Port Discovery */
- pe_dpm_request(PORT0, DPM_REQUEST_PORT_DISCOVERY);
+ pd_dpm_request(PORT0, DPM_REQUEST_PORT_DISCOVERY);
task_wait_event(10 * MSEC);
task_wait_event(10 * MSEC);