summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2021-02-24 16:18:16 -0700
committerCommit Bot <commit-bot@chromium.org>2021-03-09 23:44:36 +0000
commit1f3663c84209271a62c38308adaced5ae34032d6 (patch)
tree8729752bc21e15b0b9954b56609f7d510f4ead88
parent30ca30a3c11d98a293ec56221572b49866d29383 (diff)
downloadchrome-ec-1f3663c84209271a62c38308adaced5ae34032d6.tar.gz
TCPMv2: Add PD interface to asynchronously request TC Error Recovery
If a condition is reached outside the PD task which requires USB Type-C Error Recovery, it can now use pd_set_error_recovery() to request that the PD task execute this. Note that this will return before the error recovery has completed, which is in contrast to the suspend port behavior. BRANCH=None BUG=b:180453483 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I487e0da3ef65c201ff406500f0c95244b460afcb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718836 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/mock/usb_tc_sm_mock.c4
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c17
-rw-r--r--include/usb_pd.h10
-rw-r--r--test/usb_pe_drp_old.c5
-rw-r--r--test/usb_pe_drp_old_noextended.c5
-rw-r--r--test/usb_prl_old.c4
6 files changed, 45 insertions, 0 deletions
diff --git a/common/mock/usb_tc_sm_mock.c b/common/mock/usb_tc_sm_mock.c
index 6923e97f9d..07d861f4d4 100644
--- a/common/mock/usb_tc_sm_mock.c
+++ b/common/mock/usb_tc_sm_mock.c
@@ -181,6 +181,10 @@ void pd_set_suspend(int port, int suspend)
{
}
+void pd_set_error_recovery(int port)
+{
+}
+
enum tcpc_cc_polarity pd_get_polarity(int port)
{
return POLARITY_CC1;
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 6d9e2a7e60..7d1b18d906 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -124,6 +124,8 @@ void print_flag(int port, int set_or_clear, int flag);
/* Flag for retimer firmware update */
#define TC_FLAGS_USB_RETIMER_FW_UPDATE_RUN BIT(21)
#define TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN BIT(22)
+/* Flag for asynchronous call to request Error Recovery */
+#define TC_FLAGS_REQUEST_ERROR_RECOVERY BIT(23)
/* For checking flag_bit_names[] array */
#define TC_FLAGS_COUNT 23
@@ -320,6 +322,7 @@ static struct bit_name flag_bit_names[] = {
"USB_RETIMER_FW_UPDATE_RUN" },
{ TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN,
"USB_RETIMER_FW_UPDATE_LTD_RUN" },
+ { TC_FLAGS_REQUEST_ERROR_RECOVERY, "REQUEST_ERROR_RECOCVERY"},
};
BUILD_ASSERT(ARRAY_SIZE(flag_bit_names) == TC_FLAGS_COUNT);
@@ -1066,6 +1069,11 @@ void pd_set_suspend(int port, int suspend)
}
}
+void pd_set_error_recovery(int port)
+{
+ TC_SET_FLAG(port, TC_FLAGS_REQUEST_ERROR_RECOVERY);
+}
+
int pd_is_port_enabled(int port)
{
/*
@@ -2065,6 +2073,8 @@ static void tc_error_recovery_entry(const int port)
print_current_state(port);
pd_timer_enable(port, TC_TIMER_TIMEOUT, PD_T_ERROR_RECOVERY);
+
+ TC_CLR_FLAG(port, TC_FLAGS_REQUEST_ERROR_RECOVERY);
}
static void tc_error_recovery_run(const int port)
@@ -3699,6 +3709,13 @@ void tc_run(const int port)
set_state_tc(port, TC_DISABLED);
}
+ /* If error recovery has been requested, transition now */
+ if (TC_CHK_FLAG(port, TC_FLAGS_REQUEST_ERROR_RECOVERY)) {
+ if (IS_ENABLED(CONFIG_USB_PE_SM))
+ pe_invalidate_explicit_contract(port);
+ set_state_tc(port, TC_ERROR_RECOVERY);
+ }
+
if (IS_ENABLED(CONFIG_USBC_RETIMER_FW_UPDATE)) {
if (TC_CHK_FLAG(port, TC_FLAGS_SUSPENDED) &&
TC_CHK_FLAG(port,
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 87ba2406c3..b944900ced 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -2567,6 +2567,16 @@ int pd_rx_started(int port);
void pd_set_suspend(int port, int suspend);
/**
+ * Request Error Recovery
+ *
+ * Note that Error Recovery will happen on the next cycle of the port's PD task
+ * and may not have started yet at the time of the function return.
+ *
+ * @param port USB-C port number
+ */
+void pd_set_error_recovery(int port);
+
+/**
* Resume the PD task for a port after a period of time has elapsed.
* @param port USB-C port number
*/
diff --git a/test/usb_pe_drp_old.c b/test/usb_pe_drp_old.c
index 1c5717a341..e545667432 100644
--- a/test/usb_pe_drp_old.c
+++ b/test/usb_pe_drp_old.c
@@ -74,6 +74,11 @@ void pd_set_suspend(int port, int suspend)
}
+void pd_set_error_recovery(int port)
+{
+
+}
+
test_static void setup_source(void)
{
/* Start PE. */
diff --git a/test/usb_pe_drp_old_noextended.c b/test/usb_pe_drp_old_noextended.c
index b57f0c09bd..cefd77b7d2 100644
--- a/test/usb_pe_drp_old_noextended.c
+++ b/test/usb_pe_drp_old_noextended.c
@@ -65,6 +65,11 @@ void pd_set_suspend(int port, int suspend)
}
+void pd_set_error_recovery(int port)
+{
+
+}
+
test_static void setup_source(void)
{
/* Start PE. */
diff --git a/test/usb_prl_old.c b/test/usb_prl_old.c
index 6d6f02c6cf..b3e39b3b30 100644
--- a/test/usb_prl_old.c
+++ b/test/usb_prl_old.c
@@ -103,6 +103,10 @@ void pd_set_suspend(int port, int suspend)
{
}
+void pd_set_error_recovery(int port)
+{
+}
+
static struct pd_prl {
int rev;
int pd_enable;