From 0efc14b3c037397058cb1fd2b2abe1073904470b Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Thu, 12 Oct 2017 08:21:41 -0700 Subject: pd: Remove ACCESSORY states According to the USB-C spec, when a debug accessory is identified, we may optionally establish USB PD communication over CC. Some DTS partners (eg. servo_v4) expect us to speak PD, so let's make it so. There is no need for special ACCESSORY states, these do not exist in the PD spec. BRANCH=servo BUG=chromium:737755,b:65837068 TEST=On scarlet, attach servo_v4 and verify scarlet charges. Also verify EC and cr50 consoles are available through servo_v4. Change-Id: I59d1ca50b4766509eccf38562cdf926578138585 Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/693294 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Vincent Palatin Reviewed-on: https://chromium-review.googlesource.com/739995 --- board/eve/board.h | 1 - board/kevin/board.h | 1 - board/pyro/board.h | 1 - board/reef/board.h | 1 - board/servo_v4/board.c | 7 +-- board/servo_v4/board.h | 7 ++- board/servo_v4/usb_pd_policy.c | 6 ++ board/snappy/board.h | 1 - common/usb_pd_protocol.c | 123 ++++++++++------------------------------- include/case_closed_debug.h | 28 ---------- include/config.h | 6 -- include/usb_pd.h | 15 +++-- 12 files changed, 56 insertions(+), 141 deletions(-) diff --git a/board/eve/board.h b/board/eve/board.h index 7235ea163d..21d0a3845a 100644 --- a/board/eve/board.h +++ b/board/eve/board.h @@ -19,7 +19,6 @@ #define CONFIG_BOARD_HAS_BEFORE_RSMRST #define CONFIG_BOARD_VERSION #define CONFIG_BUTTON_COUNT 2 -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL #define CONFIG_DPTF #define CONFIG_FLASH_SIZE 0x80000 #define CONFIG_FPU diff --git a/board/kevin/board.h b/board/kevin/board.h index 33f634e8db..a0a2498945 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -108,7 +108,6 @@ #define CONFIG_TABLET_MODE_SWITCH /* USB PD config */ -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL #define CONFIG_CHARGE_MANAGER #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_ALT_MODE diff --git a/board/pyro/board.h b/board/pyro/board.h index 0ddfb2b572..d47052e5bf 100644 --- a/board/pyro/board.h +++ b/board/pyro/board.h @@ -76,7 +76,6 @@ #define GPIO_USB_CTL1 GPIO_EN_PP5000 /* USB PD config */ -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL #define CONFIG_CMD_PD_CONTROL #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP diff --git a/board/reef/board.h b/board/reef/board.h index d30a158d36..9941bd6b5c 100644 --- a/board/reef/board.h +++ b/board/reef/board.h @@ -80,7 +80,6 @@ #define CONFIG_TABLET_MODE /* USB PD config */ -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL #define CONFIG_CMD_PD_CONTROL #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c index c83c48072d..6eed57e862 100644 --- a/board/servo_v4/board.c +++ b/board/servo_v4/board.c @@ -6,7 +6,6 @@ #include "adc.h" #include "adc_chip.h" -#include "case_closed_debug.h" #include "common.h" #include "console.h" #include "ec_version.h" @@ -415,9 +414,9 @@ static void check_for_disconnect(void) ccd_keepalive_enabled = 0; } -void ccd_set_mode(enum ccd_mode new_mode) +void ccd_enable(int enable) { - if (new_mode == CCD_MODE_ENABLED) { + if (enable) { /* * Unfortunately the polarity detect is designed for real plug * events, and only accurately detects pre-connect idle. If @@ -434,7 +433,7 @@ void ccd_set_mode(enum ccd_mode new_mode) /* Allow some time following turning on of VBUS */ hook_call_deferred(&ccd_measure_sbu_data, PD_POWER_SUPPLY_TURN_ON_DELAY); - } else if (new_mode == CCD_MODE_DISABLED) { + } else { /* We are not connected to anything */ /* Disable ccd_measure_sbu deferred call always */ diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h index e79da62c7e..dfe8b77e15 100644 --- a/board/servo_v4/board.h +++ b/board/servo_v4/board.h @@ -86,7 +86,6 @@ #undef CONFIG_TASK_PROFILING #define CONFIG_USB_POWER_DELIVERY -#define CONFIG_USB_PD_DTS #define CONFIG_CMD_PD #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_DYNAMIC_SRC_CAP @@ -210,5 +209,11 @@ int pd_set_rp_rd(int port, int cc_pull, int rp_value); */ int board_get_version(void); +/** + * Enable or disable CCD + * + * @param enable Enable CCD if true, otherwise disable + */ +void ccd_enable(int enable); #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c index a4e057ef6c..9cf81a9dce 100644 --- a/board/servo_v4/usb_pd_policy.c +++ b/board/servo_v4/usb_pd_policy.c @@ -415,6 +415,10 @@ int pd_set_power_supply_ready(int port) vbus[DUT].mv = 5000; vbus[DUT].ma = 500; + /* Enable CCD, if debuggable TS attached */ + if (pd_ts_dts_plugged(DUT)) + ccd_enable(1); + return EC_SUCCESS; /* we are ready */ } @@ -424,6 +428,8 @@ void pd_power_supply_reset(int port) if (port == CHG) return; + ccd_enable(0); + /* Disable VBUS */ gpio_set_level(GPIO_DUT_CHG_EN, 0); /* Set default VBUS source to Host */ diff --git a/board/snappy/board.h b/board/snappy/board.h index c6673ae719..1e62bb0829 100644 --- a/board/snappy/board.h +++ b/board/snappy/board.h @@ -75,7 +75,6 @@ #define GPIO_USB_CTL1 GPIO_EN_PP5000 /* USB PD config */ -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL #define CONFIG_CMD_PD_CONTROL #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index d85e8ea83c..26615fd037 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -5,7 +5,6 @@ #include "battery.h" #include "board.h" -#include "case_closed_debug.h" #include "charge_manager.h" #include "charge_state.h" #include "chipset.h" @@ -113,8 +112,6 @@ static struct pd_protocol { uint8_t power_role; /* current port data role (DFP or UFP) */ uint8_t data_role; - /* port flags, see PD_FLAGS_* */ - uint16_t flags; /* 3-bit rolling message ID counter */ uint8_t msg_id; /* Port polarity : 0 => CC1 is CC line, 1 => CC2 is CC line */ @@ -125,6 +122,8 @@ static struct pd_protocol { enum pd_states last_state; /* The state to go to after timeout */ enum pd_states timeout_state; + /* port flags, see PD_FLAGS_* */ + uint32_t flags; /* Timeout for the current state. Set to 0 for no timeout. */ uint64_t timeout; /* Time for source recovery after hard reset */ @@ -171,12 +170,12 @@ static const char * const pd_state_names[] = { "DISABLED", "SUSPENDED", #ifdef CONFIG_USB_PD_DUAL_ROLE "SNK_DISCONNECTED", "SNK_DISCONNECTED_DEBOUNCE", - "SNK_ACCESSORY", "SNK_HARD_RESET_RECOVER", + "SNK_HARD_RESET_RECOVER", "SNK_DISCOVERY", "SNK_REQUESTED", "SNK_TRANSITION", "SNK_READY", "SNK_SWAP_INIT", "SNK_SWAP_SNK_DISABLE", "SNK_SWAP_SRC_DISABLE", "SNK_SWAP_STANDBY", "SNK_SWAP_COMPLETE", #endif /* CONFIG_USB_PD_DUAL_ROLE */ - "SRC_DISCONNECTED", "SRC_DISCONNECTED_DEBOUNCE", "SRC_ACCESSORY", + "SRC_DISCONNECTED", "SRC_DISCONNECTED_DEBOUNCE", "SRC_HARD_RESET_RECOVER", "SRC_STARTUP", "SRC_DISCOVERY", "SRC_NEGOCIATE", "SRC_ACCEPTED", "SRC_POWERED", "SRC_TRANSITION", "SRC_READY", "SRC_GET_SNK_CAP", "DR_SWAP", @@ -232,6 +231,15 @@ int pd_is_connected(int port) pd[port].task_state != PD_STATE_SRC_DISCONNECTED_DEBOUNCE); } +/* + * Return true if partner port is a DTS or TS capable of entering debug + * mode (eg. is presenting Rp/Rp or Rd/Rd). + */ +int pd_ts_dts_plugged(int port) +{ + return pd[port].flags & PD_FLAGS_TS_DTS_PARTNER; +} + #ifdef CONFIG_USB_PD_DUAL_ROLE void pd_vbus_low(int port) { @@ -246,17 +254,6 @@ static inline int pd_is_vbus_present(int port) return pd_snk_is_vbus_provided(port); #endif } - -static int pd_debug_acc_plugged(int port) -{ -#ifdef CONFIG_CASE_CLOSED_DEBUG_EXTERNAL - return pd[port].task_state == PD_STATE_SRC_ACCESSORY || - pd[port].task_state == PD_STATE_SNK_ACCESSORY; -#else - /* Debug accessories not supported */ - return 0; -#endif -} #endif static inline void set_state(int port, enum pd_states next_state) @@ -1272,7 +1269,7 @@ void pd_update_dual_role_config(int port) * disconnected state). */ if (pd[port].power_role == PD_ROLE_SOURCE && - ((drp_state == PD_DRP_FORCE_SINK && !pd_debug_acc_plugged(port)) || + ((drp_state == PD_DRP_FORCE_SINK && !pd_ts_dts_plugged(port)) || (drp_state == PD_DRP_TOGGLE_OFF && pd[port].task_state == PD_STATE_SRC_DISCONNECTED))) { pd[port].power_role = PD_ROLE_SINK; @@ -1722,13 +1719,18 @@ void pd_task(void) /* Debounce complete */ /* UFP is attached */ - if (new_cc_state == PD_CC_UFP_ATTACHED) { - pd[port].polarity = (cc2 == TYPEC_CC_VOLT_RD); + if (new_cc_state == PD_CC_UFP_ATTACHED || + new_cc_state == PD_CC_DEBUG_ACC) { + pd[port].polarity = (cc1 != TYPEC_CC_VOLT_RD); tcpm_set_polarity(port, pd[port].polarity); /* initial data role for source is DFP */ pd_set_data_role(port, PD_ROLE_DFP); + if (new_cc_state == PD_CC_DEBUG_ACC) + pd[port].flags |= + PD_FLAGS_TS_DTS_PARTNER; + #ifndef CONFIG_USBC_BACKWARDS_COMPATIBLE_DFP /* Enable VBUS */ if (pd_set_power_supply_ready(port)) { @@ -1755,60 +1757,10 @@ void pd_task(void) timeout = 5*MSEC; set_state(port, PD_STATE_SRC_STARTUP); } - /* Accessory is attached */ - else if (new_cc_state == PD_CC_AUDIO_ACC || - new_cc_state == PD_CC_DEBUG_ACC) { -#ifdef CONFIG_USBC_BACKWARDS_COMPATIBLE_DFP - /* Remove VBUS */ - pd_power_supply_reset(port); -#endif - /* Set the USB muxes and the default USB role */ - pd_set_data_role(port, CONFIG_USB_PD_DEBUG_DR); - -#ifdef CONFIG_USB_PD_DTS - if (new_cc_state == PD_CC_DEBUG_ACC) { - ccd_set_mode(system_is_locked() ? - CCD_MODE_PARTIAL : - CCD_MODE_ENABLED); - - /* Enable Vbus */ - pd_set_power_supply_ready(port); - /* Captive cable, CC1 always */ - pd[port].polarity = 0; - tcpm_set_polarity(port, 0); - /* Enable TCPC RX */ - if (pd_comm_enabled) - tcpm_set_rx_enable(port, 1); - pd[port].flags |= - PD_FLAGS_CHECK_DR_ROLE; - hard_reset_count = 0; - timeout = 10*MSEC; - set_state(port, PD_STATE_SRC_STARTUP); - break; - } -#endif - set_state(port, PD_STATE_SRC_ACCESSORY); - } - break; - case PD_STATE_SRC_ACCESSORY: - /* Combined audio / debug accessory state */ - timeout = 100*MSEC; - - tcpm_get_cc(port, &cc1, &cc2); - - /* If accessory becomes detached */ - if ((pd[port].cc_state == PD_CC_AUDIO_ACC && - (cc1 != TYPEC_CC_VOLT_RA || - cc2 != TYPEC_CC_VOLT_RA)) || - (pd[port].cc_state == PD_CC_DEBUG_ACC && - (cc1 != TYPEC_CC_VOLT_RD || - cc2 != TYPEC_CC_VOLT_RD))) { - set_state(port, PD_STATE_SRC_DISCONNECTED); -#ifdef CONFIG_USB_PD_DTS - ccd_set_mode(CCD_MODE_DISABLED); -#endif - timeout = 10*MSEC; - } + /* + * AUDIO_ACC will remain in this state indefinitely + * until disconnect. + */ break; case PD_STATE_SRC_HARD_RESET_RECOVER: /* Do not continue until hard reset recovery time */ @@ -2241,32 +2193,20 @@ void pd_task(void) tcpm_set_rx_enable(port, 1); /* DFP is attached */ - if (new_cc_state == PD_CC_DFP_ATTACHED) { + if (new_cc_state == PD_CC_DFP_ATTACHED || + new_cc_state == PD_CC_DEBUG_ACC) { pd[port].flags |= PD_FLAGS_CHECK_PR_ROLE | PD_FLAGS_CHECK_DR_ROLE | PD_FLAGS_CHECK_IDENTITY; + if (new_cc_state == PD_CC_DEBUG_ACC) + pd[port].flags |= + PD_FLAGS_TS_DTS_PARTNER; set_state(port, PD_STATE_SNK_DISCOVERY); timeout = 10*MSEC; hook_call_deferred( &pd_usb_billboard_deferred_data, PD_T_AME); } -#ifdef CONFIG_CASE_CLOSED_DEBUG_EXTERNAL - else if (new_cc_state == PD_CC_DEBUG_ACC) - set_state(port, PD_STATE_SNK_ACCESSORY); - break; - case PD_STATE_SNK_ACCESSORY: - /* debug accessory state */ - timeout = 100*MSEC; - - tcpm_get_cc(port, &cc1, &cc2); - - /* If accessory becomes detached */ - if (!cc_is_rp(cc1) || !cc_is_rp(cc2)) { - set_state(port, PD_STATE_SNK_DISCONNECTED); - timeout = 10*MSEC; - } -#endif break; case PD_STATE_SNK_HARD_RESET_RECOVER: if (pd[port].last_state != pd[port].task_state) @@ -2803,9 +2743,6 @@ void pd_task(void) set_state(port, PD_STATE_SRC_DISCONNECTED); /* Debouncing */ timeout = 10*MSEC; -#ifdef CONFIG_USB_PD_DTS - ccd_set_mode(CCD_MODE_DISABLED); -#endif #ifdef CONFIG_USB_PD_DUAL_ROLE /* * If Try.SRC is configured, then ATTACHED_SRC diff --git a/include/case_closed_debug.h b/include/case_closed_debug.h index b41532bc5e..6a8ce14ffc 100644 --- a/include/case_closed_debug.h +++ b/include/case_closed_debug.h @@ -7,34 +7,6 @@ #ifndef __CROS_EC_CASE_CLOSED_DEBUG_H #define __CROS_EC_CASE_CLOSED_DEBUG_H -enum ccd_mode { - /* - * The disabled mode tri-states the DP and DN lines. - */ - CCD_MODE_DISABLED, - - /* - * The partial mode allows some CCD functionality and is to be set - * when the device is write protected and a CCD cable is detected. - * This mode gives access to the APs console. - */ - CCD_MODE_PARTIAL, - - /* - * The fully enabled mode is used in factory and test lab - * configurations where it is acceptable to be able to reflash the - * device over CCD. - */ - CCD_MODE_ENABLED, - - CCD_MODE_COUNT, -}; - -/* - * Set current CCD mode, this function is idempotent. - */ -void ccd_set_mode(enum ccd_mode new_mode); - /** * Return non-zero if the CCD external interface is enabled. */ diff --git a/include/config.h b/include/config.h index d461e2e770..660f067850 100644 --- a/include/config.h +++ b/include/config.h @@ -336,9 +336,6 @@ */ #undef CONFIG_BUTTON_COUNT -/* The case close debug (CCD) feature is provided by an external chip. */ -#undef CONFIG_CASE_CLOSED_DEBUG_EXTERNAL - /* * Capsense chip has buttons, too. */ @@ -2048,9 +2045,6 @@ */ #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 bfdc55f6e6..32cba85158 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -635,7 +635,6 @@ enum pd_states { #ifdef CONFIG_USB_PD_DUAL_ROLE PD_STATE_SNK_DISCONNECTED, PD_STATE_SNK_DISCONNECTED_DEBOUNCE, - PD_STATE_SNK_ACCESSORY, PD_STATE_SNK_HARD_RESET_RECOVER, PD_STATE_SNK_DISCOVERY, PD_STATE_SNK_REQUESTED, @@ -651,7 +650,6 @@ enum pd_states { PD_STATE_SRC_DISCONNECTED, PD_STATE_SRC_DISCONNECTED_DEBOUNCE, - PD_STATE_SRC_ACCESSORY, PD_STATE_SRC_HARD_RESET_RECOVER, PD_STATE_SRC_STARTUP, PD_STATE_SRC_DISCOVERY, @@ -707,6 +705,7 @@ enum pd_states { #define PD_FLAGS_TRY_SRC (1 << 13)/* Try.SRC states are active */ #define PD_FLAGS_PARTNER_USB_COMM (1 << 14)/* port partner is USB comms */ #define PD_FLAGS_UPDATE_SRC_CAPS (1 << 15)/* send new source capabilities */ +#define PD_FLAGS_TS_DTS_PARTNER (1 << 16)/* partner has rp/rp or rd/rd */ /* Flags to clear on a disconnect */ #define PD_FLAGS_RESET_ON_DISCONNECT_MASK (PD_FLAGS_PARTNER_DR_POWER | \ PD_FLAGS_PARTNER_DR_DATA | \ @@ -721,8 +720,8 @@ enum pd_states { PD_FLAGS_VCONN_ON | \ PD_FLAGS_TRY_SRC | \ PD_FLAGS_PARTNER_USB_COMM | \ - PD_FLAGS_UPDATE_SRC_CAPS) - + PD_FLAGS_UPDATE_SRC_CAPS | \ + PD_FLAGS_TS_DTS_PARTNER) enum pd_cc_states { PD_CC_NONE, @@ -1568,6 +1567,14 @@ void pd_prepare_reset(void); */ void pd_set_new_power_request(int port); +/** + * Return true if partner port is a DTS or TS capable of entering debug + * mode (eg. is presenting Rp/Rp or Rd/Rd). + * + * @param port USB-C port number + */ +int pd_ts_dts_plugged(int port); + /* ----- Logging ----- */ #ifdef CONFIG_USB_PD_LOGGING /** -- cgit v1.2.1