summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuibin Chang <Ruibin.Chang@ite.com.tw>2019-05-21 15:25:44 +0800
committerCommit Bot <commit-bot@chromium.org>2019-06-06 17:10:21 +0000
commitc38702a1fb30f659aaf828844f78aa15361dd4f6 (patch)
treed03da5bfd026490d195f9b1fa3024bf560fdacdf
parenta0de60bc8f609ef40d7c6fc7e5d436d5a7a6078a (diff)
downloadchrome-ec-c38702a1fb30f659aaf828844f78aa15361dd4f6.tar.gz
usb/mux: Do not connect MUX when PD disconnected
When chipset power up to S5->S3 state set PD_EVENT_POWER_STATE_CHANGE, pd task set mux usb mode whether c-port is attached or not. If c-port is nothing attached at the setting moment, then mux detects nothing and goes to low power state. Plug-in type-c usb device, after debounce pass, we set mux usb mode and mux responds i2C NAK (due to in low power mode). This CL changes that do not connect MUX when PD disconnected. For example ps8751 is used for mux case. When power up(S5->S3), we should set mux none mode whether c-port is attached or not. Once type-c usb device plug-in, after cc debounce pass, we will set mux usb mode in X_DEBOUNCE_DISCONNECT state. BRANCH=None BUG=b:133196882 TEST=After console cmd reboot and reboot hard, type-c usb device plug-in on ampton and get type-c port status by "ectool usbpdmuxinfo". Change-Id: Ia538af48c450e12af1438a6aa9a6e4e426e2f616 Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/1609262 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit 30258567e5e4cdb50f4a9238b27f6ad1b064bd65) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1645638 Commit-Queue: Diana Z <dzigterman@chromium.org> Tested-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--common/usb_pd_protocol.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index e921e5eeba..dbbe837c74 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -1207,6 +1207,15 @@ static void handle_vdm_request(int port, int cnt, uint32_t *payload)
port, PD_VDO_VID(payload[0]), payload[0] & 0xFFFF);
}
+static __maybe_unused int pd_is_disconnected(int port)
+{
+ return pd[port].task_state == PD_STATE_SRC_DISCONNECTED
+#ifdef CONFIG_USB_PD_DUAL_ROLE
+ || pd[port].task_state == PD_STATE_SNK_DISCONNECTED
+#endif
+ ;
+}
+
static void set_usb_mux_with_current_data_role(int port)
{
#ifdef CONFIG_USBC_SS_MUX
@@ -1222,21 +1231,29 @@ static void set_usb_mux_with_current_data_role(int port)
}
#endif /* CONFIG_POWER_COMMON */
-#ifdef CONFIG_USBC_SS_MUX_DFP_ONLY
/*
- * Need to connect SS mux for if new data role is DFP.
- * If new data role is UFP, then disconnect the SS mux.
+ * When PD stack is disconnected, then mux should be disconnected, which
+ * is also what happens in the set_state disconnection code. Once the
+ * PD state machine progresses out of disconnect, the MUX state will
+ * be set correctly again.
*/
- if (pd[port].data_role == PD_ROLE_DFP)
- usb_mux_set(port, TYPEC_MUX_USB, USB_SWITCH_CONNECT,
+ if (pd_is_disconnected(port))
+ usb_mux_set(port, TYPEC_MUX_NONE, USB_SWITCH_DISCONNECT,
pd[port].polarity);
- else
+ /*
+ * If new data role isn't DFP and we only support DFP, also disconnect.
+ */
+ else if (IS_ENABLED(CONFIG_USBC_SS_MUX_DFP_ONLY) &&
+ pd[port].data_role != PD_ROLE_DFP)
usb_mux_set(port, TYPEC_MUX_NONE, USB_SWITCH_DISCONNECT,
pd[port].polarity);
-#else
- usb_mux_set(port, TYPEC_MUX_USB, USB_SWITCH_CONNECT,
- pd[port].polarity);
-#endif /* CONFIG_USBC_SS_MUX_DFP_ONLY */
+ /*
+ * Otherwise connect mux since we are in S3+
+ */
+ else
+ usb_mux_set(port, TYPEC_MUX_USB, USB_SWITCH_CONNECT,
+ pd[port].polarity);
+
#endif /* CONFIG_USBC_SS_MUX */
}