summaryrefslogtreecommitdiff
path: root/common/usbc/usb_tc_drp_acc_trysrc_sm.c
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@google.com>2021-02-17 15:29:37 -0700
committerCommit Bot <commit-bot@chromium.org>2021-03-02 00:12:00 +0000
commit14ec5f4bd16b3ed4f4ce1f572400b102fb93c362 (patch)
treef6c0a740011fb4090fbe02571fbe2b3b1586b967 /common/usbc/usb_tc_drp_acc_trysrc_sm.c
parentecba4b517e09173fcda50cbbf9d1c29d38ff9833 (diff)
downloadchrome-ec-14ec5f4bd16b3ed4f4ce1f572400b102fb93c362.tar.gz
TCPMv2: PD Timers - Add TC LowPowerModeDebounce to framework
BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I576fe4b2d2e48d0cd51295a2f22b91d9bb2dd28a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707809 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common/usbc/usb_tc_drp_acc_trysrc_sm.c')
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index fb8e1f8249..e2f323214d 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -423,10 +423,6 @@ static struct type_c {
uint64_t next_role_swap;
/* Generic timer */
uint64_t timeout;
- /* Time to enter low power mode */
- uint64_t low_power_time;
- /* Time to debounce exit low power mode */
- uint64_t low_power_exit_time;
/* Tasks to notify after TCPC has been reset */
int tasks_waiting_on_reset;
/* Tasks preventing TCPC from entering low power mode */
@@ -1649,7 +1645,10 @@ static void print_current_state(const int port)
static void handle_device_access(int port)
{
- tc[port].low_power_time = get_time().val + PD_LPM_DEBOUNCE_US;
+ if (IS_ENABLED(CONFIG_USB_PD_TCPC_LOW_POWER) &&
+ get_state_tc(port) == TC_LOW_POWER_MODE)
+ pd_timer_enable(port, TC_TIMER_LOW_POWER_TIME,
+ PD_LPM_DEBOUNCE_US);
}
void tc_event_check(int port, int evt)
@@ -3216,8 +3215,7 @@ __maybe_unused static void tc_low_power_mode_entry(const int port)
assert(0);
print_current_state(port);
- tc[port].low_power_time = get_time().val + PD_LPM_DEBOUNCE_US;
- tc[port].low_power_exit_time = 0;
+ pd_timer_enable(port, TC_TIMER_LOW_POWER_TIME, PD_LPM_DEBOUNCE_US);
}
__maybe_unused static void tc_low_power_mode_run(const int port)
@@ -3226,13 +3224,12 @@ __maybe_unused static void tc_low_power_mode_run(const int port)
assert(0);
if (TC_CHK_FLAG(port, TC_FLAGS_CHECK_CONNECTION)) {
- uint64_t now = get_time().val;
-
tc_start_event_loop(port);
- if (tc[port].low_power_exit_time == 0) {
- tc[port].low_power_exit_time = now
- + PD_LPM_EXIT_DEBOUNCE_US;
- } else if (now > tc[port].low_power_exit_time) {
+ if (pd_timer_is_disabled(port, TC_TIMER_LOW_POWER_EXIT_TIME)) {
+ pd_timer_enable(port, TC_TIMER_LOW_POWER_EXIT_TIME,
+ PD_LPM_EXIT_DEBOUNCE_US);
+ } else if (pd_timer_is_expired(port,
+ TC_TIMER_LOW_POWER_EXIT_TIME)) {
CPRINTS("C%d: Exit Low Power Mode", port);
check_drp_connection(port);
}
@@ -3240,9 +3237,10 @@ __maybe_unused static void tc_low_power_mode_run(const int port)
}
if (tc[port].tasks_preventing_lpm)
- tc[port].low_power_time = get_time().val + PD_LPM_DEBOUNCE_US;
+ pd_timer_enable(port, TC_TIMER_LOW_POWER_TIME,
+ PD_LPM_DEBOUNCE_US);
- if (get_time().val > tc[port].low_power_time) {
+ if (pd_timer_is_expired(port, TC_TIMER_LOW_POWER_TIME)) {
CPRINTS("C%d: TCPC Enter Low Power Mode", port);
TC_SET_FLAG(port, TC_FLAGS_LPM_ENGAGED);
TC_SET_FLAG(port, TC_FLAGS_LPM_TRANSITION);
@@ -3250,10 +3248,15 @@ __maybe_unused static void tc_low_power_mode_run(const int port)
TC_CLR_FLAG(port, TC_FLAGS_LPM_TRANSITION);
tc_pause_event_loop(port);
- tc[port].low_power_exit_time = 0;
+ pd_timer_disable(port, TC_TIMER_LOW_POWER_EXIT_TIME);
}
}
+__maybe_unused static void tc_low_power_mode_exit(const int port)
+{
+ pd_timer_disable(port, TC_TIMER_LOW_POWER_TIME);
+ pd_timer_disable(port, TC_TIMER_LOW_POWER_EXIT_TIME);
+}
/**
* Try.SRC
@@ -3870,6 +3873,7 @@ static __const_data const struct usb_state tc_states[] = {
[TC_LOW_POWER_MODE] = {
.entry = tc_low_power_mode_entry,
.run = tc_low_power_mode_run,
+ .exit = tc_low_power_mode_exit,
},
#endif /* CONFIG_USB_PD_TCPC_LOW_POWER */
#ifdef CONFIG_USB_PE_SM