From 58e18da39fb2f93d72ac8009f71cddc9e500b2f2 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 12 Jan 2017 18:38:39 -0800 Subject: [PATCH] servo_v4: pd: Added Device Test System support - Modified src attach state to enable vbus when debug accessory is detected. - servo_v4 has two pd ports, but each port requires a different default power role. Port 0 can only ever be a SNK, but port 1 which acts is intended to be a DTS port should default to a SRC so it can be be a source debug accessory. It may also act as a sink debug accessory, but is not intended to toggle automatically but will swap roles if necessary via pd role swap messaging. - Add hook for ccd enable/disable for DTS mode BUG=chrome-os-partner:61878 BRANCH=servo TEST=Manual Verfied that can still build servo_v4 project. All changes in this CL are contingent on config option CONFIG_USB_PD_DTS being enabled. Change-Id: Iab968b6fbdfc8f2d155c4f8618921b32f313b9ec Signed-off-by: Scott Reviewed-on: https://chromium-review.googlesource.com/428308 Commit-Ready: Scott Collyer Tested-by: Scott Collyer Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 31 ++++++++++++++++--------------- common/usb_pd_tcpc.c | 6 +++--- driver/tcpm/it83xx.c | 2 +- include/config.h | 3 +++ include/usb_pd.h | 9 ++++++--- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index ecd593e1e3..4fbf419cc3 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1634,13 +1634,12 @@ void pd_task(void) #endif /* Initialize PD protocol state variables for each port. */ - pd[port].power_role = PD_ROLE_DEFAULT; + pd[port].power_role = PD_ROLE_DEFAULT(port); pd[port].vdm_state = VDM_STATE_DONE; set_state(port, this_state); tcpm_select_rp_value(port, CONFIG_USB_PD_PULLUP); - tcpm_set_cc(port, PD_ROLE_DEFAULT == PD_ROLE_SOURCE ? TYPEC_CC_RP : - TYPEC_CC_RD); - + tcpm_set_cc(port, PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE ? + TYPEC_CC_RP : TYPEC_CC_RD); #ifdef CONFIG_USB_PD_ALT_MODE_DFP /* Initialize PD Policy engine */ @@ -1694,9 +1693,8 @@ void pd_task(void) (pd[port].task_state != PD_STATE_DRP_AUTO_TOGGLE)) { #endif /* Ensure CC termination is default */ - tcpm_set_cc(port, PD_ROLE_DEFAULT == PD_ROLE_SOURCE ? - TYPEC_CC_RP : - TYPEC_CC_RD); + tcpm_set_cc(port, PD_ROLE_DEFAULT(port) == + PD_ROLE_SOURCE ? TYPEC_CC_RP : TYPEC_CC_RD); /* * If we have a stable contract in the default role, @@ -1707,10 +1705,10 @@ void pd_task(void) */ if (pd[port].vdm_state == VDM_STATE_DONE && ( #ifdef CONFIG_USB_PD_DUAL_ROLE - (PD_ROLE_DEFAULT == PD_ROLE_SINK && + (PD_ROLE_DEFAULT(port) == PD_ROLE_SINK && pd[port].task_state == PD_STATE_SNK_READY) || #endif - (PD_ROLE_DEFAULT == PD_ROLE_SOURCE && + (PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE && pd[port].task_state == PD_STATE_SRC_READY))) { tcpm_set_polarity(port, pd[port].polarity); tcpm_set_msg_header(port, pd[port].power_role, @@ -1718,7 +1716,7 @@ void pd_task(void) tcpm_set_rx_enable(port, 1); } else { /* Ensure state variables are at default */ - pd[port].power_role = PD_ROLE_DEFAULT; + pd[port].power_role = PD_ROLE_DEFAULT(port); pd[port].vdm_state = VDM_STATE_DONE; set_state(port, PD_DEFAULT_STATE(port)); } @@ -1772,7 +1770,7 @@ void pd_task(void) set_state(port, PD_STATE_SRC_DISCONNECTED_DEBOUNCE); } -#ifdef CONFIG_USB_PD_DUAL_ROLE +#if defined(CONFIG_USB_PD_DUAL_ROLE) && !defined(CONFIG_USB_PD_DTS) /* * Try.SRC state is embedded here. Wait for SNK * detect, or if timer expires, transition to @@ -1876,11 +1874,14 @@ void pd_task(void) /* Remove VBUS */ pd_power_supply_reset(port); #endif - +#ifdef CONFIG_USB_PD_DTS + if (new_cc_state == PD_CC_DEBUG_ACC) + pd_set_power_supply_ready(port); +#endif /* Set the USB muxes and the default USB role */ pd_set_data_role(port, CONFIG_USB_PD_DEBUG_DR); -#ifdef CONFIG_CASE_CLOSED_DEBUG +#if defined(CONFIG_CASE_CLOSED_DEBUG) || defined(CONFIG_USB_PD_DTS) if (new_cc_state == PD_CC_DEBUG_ACC) { ccd_set_mode(system_is_locked() ? CCD_MODE_PARTIAL : @@ -1904,7 +1905,7 @@ void pd_task(void) (cc1 != TYPEC_CC_VOLT_RD || cc2 != TYPEC_CC_VOLT_RD))) { set_state(port, PD_STATE_SRC_DISCONNECTED); -#ifdef CONFIG_CASE_CLOSED_DEBUG +#if defined(CONFIG_CASE_CLOSED_DEBUG) || defined(CONFIG_USB_PD_DTS) ccd_set_mode(CCD_MODE_DISABLED); #endif timeout = 10*MSEC; @@ -2209,7 +2210,7 @@ void pd_task(void) while (pd[port].task_state == PD_STATE_SUSPENDED) task_wait_event(-1); #ifdef CONFIG_USB_PD_TCPC - pd_hw_init(port, PD_ROLE_DEFAULT); + pd_hw_init(port, PD_ROLE_DEFAULT(port)); #endif CPRINTS("TCPC p%d resumed!", port); break; diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c index 18e90c583a..db1722f2e6 100644 --- a/common/usb_pd_tcpc.c +++ b/common/usb_pd_tcpc.c @@ -1085,9 +1085,9 @@ void tcpc_init(int port) int i; /* Initialize physical layer */ - pd_hw_init(port, PD_ROLE_DEFAULT); - pd[port].cc_pull = PD_ROLE_DEFAULT == PD_ROLE_SOURCE ? TYPEC_CC_RP : - TYPEC_CC_RD; + pd_hw_init(port, PD_ROLE_DEFAULT(port)); + pd[port].cc_pull = PD_ROLE_DEFAULT(port) == + PD_ROLE_SOURCE ? TYPEC_CC_RP : TYPEC_CC_RD; #ifdef TCPC_LOW_POWER /* Don't use low power immediately after boot */ pd[port].low_power_ts.val = get_time().val + SECOND; diff --git a/driver/tcpm/it83xx.c b/driver/tcpm/it83xx.c index d31a00ecec..4c24a84b13 100644 --- a/driver/tcpm/it83xx.c +++ b/driver/tcpm/it83xx.c @@ -321,7 +321,7 @@ static void it83xx_set_cc(enum usbpd_port port, int pull) static int it83xx_tcpm_init(int port) { /* Initialize physical layer */ - it83xx_init(port, PD_ROLE_DEFAULT); + it83xx_init(port, PD_ROLE_DEFAULT(port)); return EC_SUCCESS; } diff --git a/include/config.h b/include/config.h index dd1ab1167b..51e50533ff 100644 --- a/include/config.h +++ b/include/config.h @@ -2119,6 +2119,9 @@ */ #undef CONFIG_USB_PD_DISCHARGE_TCPC +/* Define if this board is acting as a Debug Test System (DTS) */ +#undef CONFIG_USB_PD_DTS + /* Define if this board can act as a dual-role PD port (source and sink) */ #undef CONFIG_USB_PD_DUAL_ROLE diff --git a/include/usb_pd.h b/include/usb_pd.h index 940424ecfa..d415a61fc1 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -765,6 +765,7 @@ void pd_set_dual_role(enum pd_dual_role_states state); * @param port Port number from which to get role */ int pd_get_role(int port); + #endif /* Control Message type */ @@ -812,15 +813,17 @@ enum pd_data_msg_type { #define PD_ROLE_VCONN_ON 1 /* Port role at startup */ +#ifndef PD_ROLE_DEFAULT #ifdef CONFIG_USB_PD_DUAL_ROLE -#define PD_ROLE_DEFAULT PD_ROLE_SINK +#define PD_ROLE_DEFAULT(port) PD_ROLE_SINK #else -#define PD_ROLE_DEFAULT PD_ROLE_SOURCE +#define PD_ROLE_DEFAULT(port) PD_ROLE_SOURCE +#endif #endif /* Port default state at startup */ #ifdef CONFIG_USB_PD_DUAL_ROLE -#define PD_DEFAULT_STATE(port) ((PD_ROLE_DEFAULT == PD_ROLE_SOURCE) ? \ +#define PD_DEFAULT_STATE(port) ((PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE) ? \ PD_STATE_SRC_DISCONNECTED : \ PD_STATE_SNK_DISCONNECTED) #else