summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Collyer <scollyer@google.com>2019-02-21 17:36:10 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-12 07:16:16 -0700
commitb64ceedac747758de7b5323e7820c679255c164a (patch)
treee9f9c4776f174d754e579f2d45626cdde321d390
parent2e1ab32b8e5e28032dd397d9fbf06acbe19a65de (diff)
downloadchrome-ec-b64ceedac747758de7b5323e7820c679255c164a.tar.gz
usb_chg: Add USB_CHG events for data role set and CC open
The pi3usb9201 bc1.2 chip has both client and host mode support. Other bc1.2 detection chips support client mode and are triggered by VBUS detection events. To have better control of the pi3usb9201 and to prevent d+/d- data interruption, it's preferable to trigger bc1.2 mode on data role updates as the data role setting is what's most relevant to legacy bc1.2 modes. This CL adds 3 new USB_CHG events that can be set in the USB PD protocol layer when the data role is being set to sink or source and when a detach event occurs. BUG=b:124612788 BRANCH=none TEST=Tested both external chargers, adapters, and charge through hubs. Verfied that bc1.2 detection is triggered as expected when chargers are connected and verified that when the type C port is in source mode, then the pi3usb9201 is in host CDP mode. Change-Id: I9dbb441c6e226a7836220fc6abcf723a46b1a349 Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/1503953 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r--common/usb_pd_protocol.c22
-rw-r--r--include/config.h12
-rw-r--r--include/usb_charge.h3
3 files changed, 37 insertions, 0 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 9c49e104ca..2615d9089e 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -704,6 +704,15 @@ static inline void set_state(int port, enum pd_states next_state)
CEIL_REQUESTOR_PD,
CHARGE_CEIL_NONE);
#endif
+#ifdef CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER
+ /*
+ * When data role set events are used to enable BC1.2, then CC
+ * detach events are used to notify BC1.2 that it can be powered
+ * down.
+ */
+ task_set_event(USB_CHG_PORT_TO_TASK_ID(port),
+ USB_CHG_EVENT_CC_OPEN, 0);
+#endif /* CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER */
#ifdef CONFIG_USBC_VCONN
set_vconn(port, 0);
#endif /* defined(CONFIG_USBC_VCONN) */
@@ -1243,6 +1252,19 @@ static void pd_set_data_role(int port, int role)
set_usb_mux_with_current_data_role(port);
pd_update_roles(port);
+#ifdef CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER
+ /*
+ * For BC1.2 detection that is triggered on data role change events
+ * instead of VBUS changes, need to set an event to wake up the USB_CHG
+ * task and indicate the current data role.
+ */
+ if (role == PD_ROLE_UFP)
+ task_set_event(USB_CHG_PORT_TO_TASK_ID(port),
+ USB_CHG_EVENT_DR_UFP, 0);
+ else if (role == PD_ROLE_DFP)
+ task_set_event(USB_CHG_PORT_TO_TASK_ID(port),
+ USB_CHG_EVENT_DR_DFP, 0);
+#endif /* CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER */
}
void pd_execute_hard_reset(int port)
diff --git a/include/config.h b/include/config.h
index 9ff7306a76..c4428c8ea9 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3526,6 +3526,12 @@
/* Common USB / BC1.2 charger detection routines */
#undef CONFIG_USB_CHARGER
+/*
+ * Used for bc1.2 chips that need to be triggered from data role swaps instead
+ * of just VBUS changes.
+ */
+#undef CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER
+
/* External BC1.2 charger detection devices. */
#undef CONFIG_BC12_DETECT_MAX14637
#undef CONFIG_BC12_DETECT_PI3USB9201
@@ -4104,6 +4110,12 @@
#endif
/*****************************************************************************/
+/* Define derived config options for BC1.2 detection */
+#ifdef CONFIG_BC12_DETECT_PI3USB9201
+#define CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER
+#endif
+
+/*****************************************************************************/
/*
* Handle task-dependent configs.
*
diff --git a/include/usb_charge.h b/include/usb_charge.h
index a974f7511e..de65725d0a 100644
--- a/include/usb_charge.h
+++ b/include/usb_charge.h
@@ -52,6 +52,9 @@ int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode mode,
#define USB_CHG_EVENT_BC12 TASK_EVENT_CUSTOM(1)
#define USB_CHG_EVENT_VBUS TASK_EVENT_CUSTOM(2)
#define USB_CHG_EVENT_INTR TASK_EVENT_CUSTOM(4)
+#define USB_CHG_EVENT_DR_UFP TASK_EVENT_CUSTOM(8)
+#define USB_CHG_EVENT_DR_DFP TASK_EVENT_CUSTOM(16)
+#define USB_CHG_EVENT_CC_OPEN TASK_EVENT_CUSTOM(32)
#endif
/*