From 37ba1a68353bcc32520f82286c30647188558350 Mon Sep 17 00:00:00 2001 From: Denis Brockus Date: Tue, 2 Mar 2021 12:04:03 -0700 Subject: TCPMv2: PD Timers - Allow StateMachine timer group range disables BUG=none BRANCH=none TEST=normal USB-C operation Signed-off-by: Denis Brockus Change-Id: I9c5bc90cc68ba424ad7632c10ba513103288b414 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2729620 Commit-Queue: Denis Brockus Tested-by: Denis Brockus Reviewed-by: Diana Z --- common/usbc/usb_pd_timer.c | 26 ++++++++++++++++++++++++++ common/usbc/usb_pe_drp_sm.c | 5 +---- common/usbc/usb_prl_sm.c | 2 ++ include/usb_pd_timer.h | 22 ++++++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/common/usbc/usb_pd_timer.c b/common/usbc/usb_pd_timer.c index e06de20389..67a574904f 100644 --- a/common/usbc/usb_pd_timer.c +++ b/common/usbc/usb_pd_timer.c @@ -151,6 +151,32 @@ void pd_timer_disable(int port, enum pd_task_timer timer) PD_SET_DISABLED(port, mask); } +void pd_timer_disable_range(int port, enum pd_timer_range range) +{ + int start, end; + enum pd_task_timer timer; + + switch (range) { + case PE_TIMER_RANGE: + start = PE_TIMER_START; + end = PE_TIMER_END; + break; + case PR_TIMER_RANGE: + start = PR_TIMER_START; + end = PR_TIMER_END; + break; + case TC_TIMER_RANGE: + start = TC_TIMER_START; + end = TC_TIMER_END; + break; + default: + return; + } + + for (timer = start; timer <= end; ++timer) + pd_timer_disable(port, timer); +} + bool pd_timer_is_disabled(int port, enum pd_task_timer timer) { uint32_t mask = 1 << timer; diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index ff42152a2b..b883351d84 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -739,10 +739,7 @@ static void pe_init(int port) pe[port].flags = 0; pe[port].dpm_request = 0; pe[port].dpm_curr_request = 0; - pd_timer_disable(port, PE_TIMER_NO_RESPONSE); - pd_timer_disable(port, PE_TIMER_SINK_REQUEST); - pd_timer_disable(port, PE_TIMER_SOURCE_CAP); - pd_timer_disable(port, PE_TIMER_WAIT_AND_ADD_JITTER); + pd_timer_disable_range(port, PE_TIMER_RANGE); pe[port].data_role = pd_get_data_role(port); pe[port].tx_type = TCPC_TX_INVALID; pe[port].events = 0; diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c index 9c9292b256..b27c1d4f2a 100644 --- a/common/usbc/usb_prl_sm.c +++ b/common/usbc/usb_prl_sm.c @@ -566,6 +566,8 @@ static void prl_init(int port) prl_tx[port].msg_id_counter[i] = 0; } + pd_timer_disable_range(port, PR_TIMER_RANGE); + /* Clear state machines and set initial states */ prl_tx[port].ctx = cleared; set_state_prl_tx(port, PRL_TX_PHY_LAYER_RESET); diff --git a/include/usb_pd_timer.h b/include/usb_pd_timer.h index ea0b302e17..5757bd7ada 100644 --- a/include/usb_pd_timer.h +++ b/include/usb_pd_timer.h @@ -196,6 +196,20 @@ enum pd_task_timer { }; BUILD_ASSERT(PD_TIMER_COUNT <= 32); +enum pd_timer_range { + PE_TIMER_RANGE, + PR_TIMER_RANGE, + TC_TIMER_RANGE, +}; +#define PE_TIMER_START PE_TIMER_BIST_CONT_MODE +#define PE_TIMER_END PE_TIMER_WAIT_AND_ADD_JITTER + +#define PR_TIMER_START PR_TIMER_CHUNK_SENDER_RESPONSE +#define PR_TIMER_END PR_TIMER_TCPC_TX_TIMEOUT + +#define TC_TIMER_START TC_TIMER_CC_DEBOUNCE +#define TC_TIMER_END TC_TIMER_VBUS_DEBOUNCE + /* * pd_timer_init * Initialize Power Delivery Timer module @@ -223,6 +237,14 @@ void pd_timer_enable(int port, enum pd_task_timer timer, uint32_t expires_us); */ void pd_timer_disable(int port, enum pd_task_timer timer); +/* + * pd_timer_disable_range + * Disable all of the timers in a group range + * + * @param port USB-C port number + * @param range Group range to disable + */ +void pd_timer_disable_range(int port, enum pd_timer_range range); /* * pd_timer_is_disabled -- cgit v1.2.1