diff options
author | Ruibin Chang <Ruibin.Chang@ite.com.tw> | 2018-12-21 10:26:54 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-04 15:30:57 -0800 |
commit | a85c958633de765e529f2fb539fdc130dd99a6a2 (patch) | |
tree | 0a473a25b24b1a7d29a244ce7642bef9d7eea7eb | |
parent | 08803b0ac80815332b07a5d8ecf3aa3c830665b8 (diff) | |
download | chrome-ec-a85c958633de765e529f2fb539fdc130dd99a6a2.tar.gz |
common/usb_pd_protocol: Try.SRC to TryWait.SNK timeout
The port shall transition to TryWait.SNK after tDRPTry
(75~150ms) and the SRC.Rd state has not been detected and
Vbus is within vSafe0V, or after tTryTimeout(550~1100ms)
and the SRC.Rd state has not been detected. This define
in USB Type-C 1.3 spec section 4.5.2.2.10.2.
BRANCH=None
BUG=None
TEST=GRL USBPD test
Change-Id: I35be7acf24eb360232b1f22a43abb8c1a1dcde99
Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw>
Reviewed-on: https://chromium-review.googlesource.com/1381592
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | common/usb_pd_protocol.c | 69 | ||||
-rw-r--r-- | include/usb_pd.h | 3 |
2 files changed, 51 insertions, 21 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 53b06b800e..72c88c10d4 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -184,6 +184,7 @@ static struct pd_protocol { int prev_request_mv; /* Time for Try.SRC states */ uint64_t try_src_marker; + uint64_t try_timeout; #endif #ifdef CONFIG_USB_PD_TCPC_LOW_POWER @@ -2891,32 +2892,58 @@ void pd_task(void *u) pd[port].cc_state = PD_CC_NONE; set_state(port, PD_STATE_SRC_DISCONNECTED_DEBOUNCE); + break; } #if defined(CONFIG_USB_PD_DUAL_ROLE) + now = get_time(); /* - * Try.SRC state is embedded here. Wait for SNK - * detect, or if timer expires, transition to - * SNK_DISCONNETED. - * - * If Try.SRC state is not active, then this block - * handles the normal DRP toggle from SRC->SNK + * Try.SRC state is embedded here. The port + * shall transition to TryWait.SNK after + * tDRPTry (PD_T_DRP_TRY) and Vbus is within + * vSafe0V, or after tTryTimeout + * (PD_T_TRY_TIMEOUT). Otherwise we should stay + * within Try.SRC (break). */ - else if ((pd[port].flags & PD_FLAGS_TRY_SRC && - get_time().val >= pd[port].try_src_marker) || - (!(pd[port].flags & PD_FLAGS_TRY_SRC) && - drp_state[port] != PD_DRP_FORCE_SOURCE && - drp_state[port] != PD_DRP_FREEZE && - get_time().val >= next_role_swap)) { - pd_set_power_role(port, PD_ROLE_SINK); + if (pd[port].flags & PD_FLAGS_TRY_SRC) { + if (now.val < pd[port].try_src_marker) { + break; + } else if (now.val < pd[port].try_timeout) { + if (pd_is_vbus_present(port)) + break; + } + + /* + * Transition to TryWait.SNK now, so set + * state and update src marker time. + */ set_state(port, PD_STATE_SNK_DISCONNECTED); + pd_set_power_role(port, PD_ROLE_SINK); tcpm_set_cc(port, TYPEC_CC_RD); - next_role_swap = get_time().val + PD_T_DRP_SNK; - pd[port].try_src_marker = get_time().val - + PD_T_DEBOUNCE; - - /* Swap states quickly */ - timeout = 2*MSEC; + pd[port].try_src_marker = + get_time().val + PD_T_DEBOUNCE; + timeout = 2 * MSEC; + break; } + + /* + * If Try.SRC state is not active, then handle + * the normal DRP toggle from SRC->SNK. + */ + if (now.val < next_role_swap || + drp_state[port] == PD_DRP_FORCE_SOURCE || + drp_state[port] == PD_DRP_FREEZE) + break; + + /* + * Transition to SNK now, so set state and + * update next role swap time. + */ + set_state(port, PD_STATE_SNK_DISCONNECTED); + pd_set_power_role(port, PD_ROLE_SINK); + tcpm_set_cc(port, TYPEC_CC_RD); + next_role_swap = get_time().val + PD_T_DRP_SNK; + /* Swap states quickly */ + timeout = 2 * MSEC; #endif break; case PD_STATE_SRC_DISCONNECTED_DEBOUNCE: @@ -3466,7 +3493,9 @@ void pd_task(void *u) * then force attempt to connect as source. */ pd[port].try_src_marker = get_time().val - + PD_T_TRY_SRC; + + PD_T_DRP_TRY; + pd[port].try_timeout = get_time().val + + PD_T_TRY_TIMEOUT; /* Swap roles to source */ pd_set_power_role(port, PD_ROLE_SOURCE); tcpm_set_cc(port, TYPEC_CC_RP); diff --git a/include/usb_pd.h b/include/usb_pd.h index ceafd18c9d..f57d8edbb5 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -176,7 +176,8 @@ enum pd_rx_errors { #define PD_T_BIST_TRANSMIT (50*MSEC) /* 50ms (used for task_wait arg) */ #define PD_T_BIST_RECEIVE (60*MSEC) /* 60ms (max time to process bist) */ #define PD_T_VCONN_SOURCE_ON (100*MSEC) /* 100ms */ -#define PD_T_TRY_SRC (125*MSEC) /* Max time for Try.SRC state */ +#define PD_T_DRP_TRY (125*MSEC) /* btween 75 and 150ms(monitor Vbus) */ +#define PD_T_TRY_TIMEOUT (550*MSEC) /* between 550ms and 1100ms */ #define PD_T_TRY_WAIT (600*MSEC) /* Max time for TryWait.SNK state */ #define PD_T_SINK_REQUEST (100*MSEC) /* Wait 100ms before next request */ |