From 522979dc23224b7c1f9d4e844f4965cc17854fdd Mon Sep 17 00:00:00 2001 From: Denis Brockus Date: Thu, 26 Mar 2020 12:41:56 -0600 Subject: [PATCH] tcpmv2: reduce zork specific auto discharge disconnect code Removing the conditional code to find the specifics that broke waddledoo and then fix that. BUG=b:152616398 b:152444591 b:150110431 b:150913968 b:151152817 BRANCH=none TEST=verify trembyle and waddledoo Signed-off-by: Denis Brockus Change-Id: Ieb88540b2298c3b999ab27ea78285f7f1c34bff6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2121633 Reviewed-by: Denis Brockus Reviewed-by: Diana Z Commit-Queue: Denis Brockus Commit-Queue: Diana Z Tested-by: Denis Brockus Auto-Submit: Denis Brockus --- baseboard/zork/baseboard.h | 1 - common/usbc/usb_tc_drp_acc_trysrc_sm.c | 60 ++------------ driver/tcpm/nct38xx.c | 103 ------------------------- driver/tcpm/tcpci.c | 12 --- driver/tcpm/tcpci.h | 2 - driver/tcpm/tcpm.h | 14 ---- include/config.h | 3 - include/usb_pd_tcpm.h | 19 ----- 8 files changed, 6 insertions(+), 208 deletions(-) diff --git a/baseboard/zork/baseboard.h b/baseboard/zork/baseboard.h index 31050f7adc..ae7ecae512 100644 --- a/baseboard/zork/baseboard.h +++ b/baseboard/zork/baseboard.h @@ -125,7 +125,6 @@ #ifndef CONFIG_USB_PD_TCPMV2 #define CONFIG_USB_PD_TCPMV1 #else - #define CONFIG_ZORK_AUTO_DISCHARGE #define CONFIG_USB_PD_DECODE_SOP #define CONFIG_USB_DRP_ACC_TRYSRC diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 7fffeb5bf8..9800dd3486 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -1642,11 +1642,6 @@ static void tc_unattached_snk_entry(const int port) if (IS_ENABLED(CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER)) bc12_role_change_handler(port); -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - /* VBus should be SafeV0, turn off auto discharge disconnect */ - tcpm_enable_auto_discharge_disconnect(port, 0); -#endif - if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) charge_manager_update_dualrole(port, CAP_UNKNOWN); @@ -1665,6 +1660,9 @@ static void tc_unattached_snk_entry(const int port) CLR_ALL_BUT_LPM_FLAGS(port); tc_enable_pd(port, 0); } + + /* Turn on auto discharge disconnect */ + tcpm_enable_auto_discharge_disconnect(port, 1); } static void tc_unattached_snk_run(const int port) @@ -1696,8 +1694,6 @@ static void tc_unattached_snk_run(const int port) if (drp_state[port] == PD_DRP_TOGGLE_ON && TC_CHK_FLAG(port, TC_FLAGS_AUTO_TOGGLE_SUPPORTED) && cc_is_open(cc1, cc2)) { - -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* * We are disconnected and going to DRP * PC.AutoDischargeDisconnect=0b @@ -1707,8 +1703,6 @@ static void tc_unattached_snk_run(const int port) */ tcpm_enable_auto_discharge_disconnect(port, 0); tcpm_set_connection(port, TYPEC_CC_RD, 0); -#endif - set_state_tc(port, TC_DRP_AUTO_TOGGLE); return; } @@ -1735,15 +1729,11 @@ static void tc_unattached_snk_run(const int port) #ifdef CONFIG_USB_PD_TCPC_LOW_POWER else if (drp_state[port] == PD_DRP_FORCE_SINK || drp_state[port] == PD_DRP_TOGGLE_OFF) { - -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* * We are disconnecting without DRP. * PC.AutoDischargeDisconnect=0b */ tcpm_enable_auto_discharge_disconnect(port, 0); -#endif - set_state_tc(port, TC_LOW_POWER_MODE); } #endif @@ -1906,11 +1896,6 @@ static void tc_attached_snk_entry(const int port) /* Enable PD */ if (IS_ENABLED(CONFIG_USB_PE_SM)) tc_enable_pd(port, 1); - -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - /* VBus should be powered, turn on auto discharge disconnect */ - tcpm_enable_auto_discharge_disconnect(port, 1); -#endif } static void tc_attached_snk_run(const int port) @@ -2350,11 +2335,6 @@ static void tc_unattached_src_entry(const int port) if (IS_ENABLED(CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER)) bc12_role_change_handler(port); -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - /* VBus should be SafeV0, turn off auto discharge disconnect */ - tcpm_enable_auto_discharge_disconnect(port, 0); -#endif - if (IS_ENABLED(CONFIG_USBC_PPC)) { /* There is no sink connected. */ ppc_sink_is_connected(port, 0); @@ -2375,6 +2355,9 @@ static void tc_unattached_src_entry(const int port) } tc[port].next_role_swap = get_time().val + PD_T_DRP_SRC; + + /* Turn on auto discharge disconnect */ + tcpm_enable_auto_discharge_disconnect(port, 1); } static void tc_unattached_src_run(const int port) @@ -2423,8 +2406,6 @@ static void tc_unattached_src_run(const int port) else if (drp_state[port] == PD_DRP_TOGGLE_ON && TC_CHK_FLAG(port, TC_FLAGS_AUTO_TOGGLE_SUPPORTED) && cc_is_open(cc1, cc2)) { - -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* * We are disconnected and going to DRP * PC.AutoDischargeDisconnect=0b @@ -2435,8 +2416,6 @@ static void tc_unattached_src_run(const int port) */ tcpm_enable_auto_discharge_disconnect(port, 0); tcpm_set_connection(port, TYPEC_CC_RP, 0); -#endif - set_state_tc(port, TC_DRP_AUTO_TOGGLE); } #endif @@ -2444,15 +2423,11 @@ static void tc_unattached_src_run(const int port) #ifdef CONFIG_USB_PD_TCPC_LOW_POWER else if (drp_state[port] == PD_DRP_FORCE_SOURCE || drp_state[port] == PD_DRP_TOGGLE_OFF) { - -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* * We are disconnecting without DRP. * PC.AutoDischargeDisconnect=0b */ tcpm_enable_auto_discharge_disconnect(port, 0); -#endif - set_state_tc(port, TC_LOW_POWER_MODE); } #endif @@ -2632,11 +2607,6 @@ static void tc_attached_src_entry(const int port) if (IS_ENABLED(CONFIG_USBC_PPC)) ppc_sink_is_connected(port, 1); -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - /* VBus should be powered, turn on auto discharge disconnect */ - tcpm_enable_auto_discharge_disconnect(port, 1); -#endif - /* * Only notify if we're not performing a power role swap. During a * power role swap, the port partner is not disconnecting/connecting. @@ -2874,33 +2844,23 @@ static void tc_drp_auto_toggle_run(const int port) set_state_tc(port, PD_DEFAULT_STATE(port)); break; case DRP_TC_UNATTACHED_SNK: -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* * New SNK connection. * Set RC.CC1 & RC.CC2 per decision * Set RC.DRP=0 * Set TCPC_CONTROl.PlugOrientation - * PC.AutoDischargeDisconnect=1b */ tcpm_set_connection(port, TYPEC_CC_RD, 1); - tcpm_enable_auto_discharge_disconnect(port, 1); -#endif - set_state_tc(port, TC_UNATTACHED_SNK); break; case DRP_TC_UNATTACHED_SRC: -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* * New SRC connection. * Set RC.CC1 & RC.CC2 per decision * Set RC.DRP=0 * Set TCPC_CONTROl.PlugOrientation - * PC.AutoDischargeDisconnect=1b */ tcpm_set_connection(port, TYPEC_CC_RP, 1); - tcpm_enable_auto_discharge_disconnect(port, 1); -#endif - set_state_tc(port, TC_UNATTACHED_SRC); break; case DRP_TC_DRP_AUTO_TOGGLE: @@ -3227,11 +3187,7 @@ static void tc_cc_rd_entry(const int port) * Both CC1 and CC2 pins shall be independently terminated to * ground through Rd. */ -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - tcpm_set_new_connection(port, TYPEC_CC_RD); -#else tcpm_set_cc(port, TYPEC_CC_RD); -#endif } @@ -3253,11 +3209,7 @@ static void tc_cc_rp_entry(const int port) * up through Rp. */ tcpm_select_rp_value(port, CONFIG_USB_PD_PULLUP); -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - tcpm_set_new_connection(port, TYPEC_CC_RP); -#else tcpm_set_cc(port, TYPEC_CC_RP); -#endif } /** diff --git a/driver/tcpm/nct38xx.c b/driver/tcpm/nct38xx.c index d8bc52ee58..c9e78935d0 100644 --- a/driver/tcpm/nct38xx.c +++ b/driver/tcpm/nct38xx.c @@ -119,103 +119,6 @@ static void nct38xx_tcpc_alert(int port) } -#ifndef CONFIG_ZORK_AUTO_DISCHARGE -#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -static int nct38xx_set_new_connection(int port, - enum tcpc_cc_pull pull) -{ - int rv; - int role; - - /* Get the ROLE CONTROL value */ - rv = tcpc_read(port, TCPC_REG_ROLE_CTRL, &role); - if (rv) - return rv; - - if (role & TCPC_REG_ROLE_CTRL_DRP_MASK) { - /* - * If DRP is set, the CC pins shall stay in - * Potential_Connect_as_Src or Potential_Connect_as_Sink - * until directed otherwise. - * - * Set RC.CC1 & RC.CC2 per potential decision - * Set RC.DRP=0 - */ - enum tcpc_cc_pull cc1_pull, cc2_pull; - enum tcpc_cc_voltage_status cc1, cc2; - - rv = nct38xx_tcpm_drv.get_cc(port, &cc1, &cc2); - if (rv) - return rv; - - switch (cc1) { - case TYPEC_CC_VOLT_OPEN: - cc1_pull = TYPEC_CC_OPEN; - break; - case TYPEC_CC_VOLT_RA: - cc1_pull = TYPEC_CC_RA; - break; - case TYPEC_CC_VOLT_RD: - cc1_pull = TYPEC_CC_RP; - break; - case TYPEC_CC_VOLT_RP_DEF: - case TYPEC_CC_VOLT_RP_1_5: - case TYPEC_CC_VOLT_RP_3_0: - cc1_pull = TYPEC_CC_RD; - break; - default: - return EC_ERROR_UNKNOWN; - } - - switch (cc2) { - case TYPEC_CC_VOLT_OPEN: - cc2_pull = TYPEC_CC_OPEN; - break; - case TYPEC_CC_VOLT_RA: - cc2_pull = TYPEC_CC_RA; - break; - case TYPEC_CC_VOLT_RD: - cc2_pull = TYPEC_CC_RP; - break; - case TYPEC_CC_VOLT_RP_DEF: - case TYPEC_CC_VOLT_RP_1_5: - case TYPEC_CC_VOLT_RP_3_0: - cc2_pull = TYPEC_CC_RD; - break; - default: - return EC_ERROR_UNKNOWN; - } - - /* Set the CC lines */ - rv = tcpc_write(port, TCPC_REG_ROLE_CTRL, - TCPC_REG_ROLE_CTRL_SET(0, - CONFIG_USB_PD_PULLUP, - cc1_pull, cc2_pull)); - if (rv) - return rv; - } else { - /* - * DRP is not set. This would happen if DRP is not enabled or - * was turned off and we did not have a connection. We have - * to manually turn off that we are looking for a connection - * and set both CC lines to the pull value. - */ - rv = tcpc_update8(port, - TCPC_REG_TCPC_CTRL, - TCPC_REG_TCPC_CTRL_EN_LOOK4CONNECTION_ALERT, - MASK_CLR); - if (rv) - return rv; - - /* Set the CC lines */ - rv = nct38xx_tcpm_drv.set_cc(port, pull); - if (rv) - return rv; - } - return EC_SUCCESS; -} -#endif -#else static __maybe_unused int nct3807_tcpc_drp_toggle(int port) { int rv; @@ -236,7 +139,6 @@ static __maybe_unused int nct3807_tcpc_drp_toggle(int port) return rv; } -#endif const struct tcpm_drv nct38xx_tcpm_drv = { .init = &nct38xx_tcpm_init, @@ -260,14 +162,9 @@ const struct tcpm_drv nct38xx_tcpm_drv = { .tcpc_enable_auto_discharge_disconnect = &tcpci_tcpc_enable_auto_discharge_disconnect, #ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - .drp_toggle = &tcpci_tcpc_drp_toggle, - .set_new_connection = &nct38xx_set_new_connection, -#else .drp_toggle = &nct3807_tcpc_drp_toggle, .set_connection = &tcpci_tcpc_set_connection, #endif -#endif #ifdef CONFIG_USBC_PPC .set_snk_ctrl = &tcpci_tcpm_set_snk_ctrl, .set_src_ctrl = &tcpci_tcpm_set_src_ctrl, diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index 80143de61d..4a9e8abe6f 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -380,7 +380,6 @@ int tcpci_tcpc_drp_toggle(int port) if (rv) return rv; -#ifdef CONFIG_ZORK_AUTO_DISCHARGE /* Set up to catch LOOK4CONNECTION alerts */ rv = tcpc_update8(port, TCPC_REG_TCPC_CTRL, @@ -388,7 +387,6 @@ int tcpci_tcpc_drp_toggle(int port) MASK_SET); if (rv) return rv; -#endif /* Set Look4Connection command */ rv = tcpc_write(port, TCPC_REG_COMMAND, @@ -397,7 +395,6 @@ int tcpci_tcpc_drp_toggle(int port) return rv; } -#ifdef CONFIG_ZORK_AUTO_DISCHARGE int tcpci_tcpc_set_connection(int port, enum tcpc_cc_pull pull, int connect) @@ -512,7 +509,6 @@ int tcpci_tcpc_set_connection(int port, return rv; } #endif -#endif #ifdef CONFIG_USB_PD_TCPC_LOW_POWER int tcpci_enter_low_power_mode(int port) @@ -1179,17 +1175,9 @@ int tcpci_tcpm_init(int port) * Alert assertion when CC_STATUS.Looking4Connection changes state. */ if (tcpc_config[port].flags & TCPC_FLAGS_TCPCI_REV2_0) { -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - int regval; - - error = tcpc_read(port, TCPC_REG_TCPC_CTRL, ®val); - regval |= TCPC_REG_TCPC_CTRL_EN_LOOK4CONNECTION_ALERT; - error |= tcpc_write(port, TCPC_REG_TCPC_CTRL, regval); -#else error = tcpc_update8(port, TCPC_REG_TCPC_CTRL, TCPC_REG_TCPC_CTRL_EN_LOOK4CONNECTION_ALERT, MASK_SET); -#endif if (error) CPRINTS("C%d: Failed to init TCPC_CTRL!", port); } diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h index 9034152e21..813c3026d4 100644 --- a/driver/tcpm/tcpci.h +++ b/driver/tcpm/tcpci.h @@ -222,11 +222,9 @@ int tcpci_tcpm_release(int port); #ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE int tcpci_set_role_ctrl(int port, int toggle, int rp, int pull); int tcpci_tcpc_drp_toggle(int port); -#ifdef CONFIG_ZORK_AUTO_DISCHARGE int tcpci_tcpc_set_connection(int port, enum tcpc_cc_pull pull, int connect); #endif -#endif #ifdef CONFIG_USB_PD_TCPC_LOW_POWER int tcpci_enter_low_power_mode(int port); #endif diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h index 0e3e2c62f5..f9453d418c 100644 --- a/driver/tcpm/tcpm.h +++ b/driver/tcpm/tcpm.h @@ -178,19 +178,6 @@ static inline int tcpm_set_cc(int port, int pull) return tcpc_config[port].drv->set_cc(port, pull); } -#ifndef CONFIG_ZORK_AUTO_DISCHARGE -static inline int tcpm_set_new_connection(int port, - enum tcpc_cc_pull pull) -{ - const struct tcpm_drv *tcpc = tcpc_config[port].drv; - - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE) && - tcpc->set_new_connection) - return tcpc->set_new_connection(port, pull); - else - return tcpc->set_cc(port, pull); -} -#else static inline int tcpm_set_connection(int port, enum tcpc_cc_pull pull, int connect) @@ -202,7 +189,6 @@ static inline int tcpm_set_connection(int port, return tcpc->set_connection(port, pull, connect); return EC_SUCCESS; } -#endif static inline int tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) { diff --git a/include/config.h b/include/config.h index 9c5c7e3ca8..139809a918 100644 --- a/include/config.h +++ b/include/config.h @@ -3662,9 +3662,6 @@ #define CONFIG_USB_PRL_SM #define CONFIG_USB_PE_SM -/* Enables Zork Auto Discharge Disconnect Changes */ -#undef CONFIG_ZORK_AUTO_DISCHARGE - /* Enables PD Console commands */ #define CONFIG_USB_PD_CONSOLE_CMD diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 39eab7e63b..35f9cccb47 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -319,24 +319,6 @@ struct tcpm_drv { void (*tcpc_enable_auto_discharge_disconnect)(int port, int enable); -#ifndef CONFIG_ZORK_AUTO_DISCHARGE - /** - * Set new connection - * There is a new connection. May have to handle differently - * if we were performing auto-toggle. Allow a driver to do - * any work required to leave the unattached auto-toggle mode - * as well as setting the CC lines. If auto-toggle is not - * being used or was not the cause of the new connection - * detection then set both CC lines to the passed pull. - * - * @param port Type-C port number - * @param pull enum tcpc_cc_pull of CC lines - * - * @return EC_SUCCESS or error - */ - int (*set_new_connection)(int port, - enum tcpc_cc_pull pull); -#else /** * Set connection * If this is a disconnect, set the ROLE_CONTROL, otherwise @@ -356,7 +338,6 @@ struct tcpm_drv { int (*set_connection)(int port, enum tcpc_cc_pull pull, int connect); -#endif #ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE /**