summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2017-12-04 15:14:33 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-01-17 20:20:26 -0800
commitb264288756ab77c2ef7950b19bcca99a15e2d5ce (patch)
tree3f00ada91c2adc40fc14709670950a08cec3286d /include
parent66d7782a7b20fd974b18baeefb5e79feae80fb40 (diff)
downloadchrome-ec-b264288756ab77c2ef7950b19bcca99a15e2d5ce.tar.gz
USB PD: PPC: Add overcurrent handling.
The Type-C Power Path Controllers provide overcurrent protection. This commit adds support into the USB PD task for overcurrent events while we are in source role. The USB PD 3.0 spec recommends that ports issue a hard reset when an overcurrent condition occurs on a port. Additionally, we'll allow a source port to overcurrent 3 times before latching off VBUS from the port entirely. The source path will be re-enabled after ~1s after each overcurrent event. BUG=b:69935262,b:114680657 BRANCH=None TEST=Boot to ChromeOS in grabbiter. No overcurrent events reported when the sink is drawing <= 3.20 A. Overcurrent events are reported when the sink is drawing > 3.25 A. After 3 reports, the port is latched off and power delivery is stopped. The port is re-enabled only after the sink is disconnected. Also when the sink is drawing current at 3.24 A, there is one report of overcurrent. The port gets disabled in response to that event. But the port is re-enabled after 1 second since overcurrent event is reported only once. After the port is re-enabled, the sink is able to draw the set current. When the overcurrent event is reported, I can see in the kernel logs that the overcurrent condition is detected by the kernel. EC Logs: [3391.984462 C1: PPC detected Vbus overcurrent!] [3391.984953 C1: overcurrent!] [3392.044935 C1: PPC detected Vbus overcurrent!] [3392.045425 C1: overcurrent!] [3392.061404 C1: PPC detected Vbus overcurrent!] [3392.061894 C1: overcurrent!] [3392.062142 C1: OC event limit reached! Source path disabled until physical disconnect.] [3392.077226 C1: PPC detected Vbus overcurrent!] [3392.077532 C1: overcurrent!] [3392.077891 C1: OC event limit reached! Source path disabled until physical disconnect.] [3392.092660 C1: PPC detected Vbus overcurrent!] [3392.092966 C1: overcurrent!] [3392.093213 C1: OC event limit reached! Source path disabled until physical disconnect.] Kernel Logs: [ 3356.560456] usb usb2-port1: over-current condition [ 3356.768434] usb usb2-port2: over-current condition [ 3356.976446] usb usb2-port4: over-current condition [ 3357.184441] usb usb2-port5: over-current condition [ 3357.392445] usb usb2-port6: over-current condition Change-Id: Ib070f261e98264cd88725ebce7d10e0798267e3b Signed-off-by: Aseda Aboagye <aaboagye@google.com> Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1286300 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/807633 Commit-Ready: Karthikeyan Ramasubramanian <kramasub@chromium.org> Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/usb_pd.h9
-rw-r--r--include/usbc_ppc.h74
2 files changed, 70 insertions, 13 deletions
diff --git a/include/usb_pd.h b/include/usb_pd.h
index d87fcc8fa4..5ae89696dd 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -48,6 +48,7 @@ enum pd_rx_errors {
*/
#define PD_EVENT_DEVICE_ACCESSED (1<<7)
#define PD_EVENT_POWER_STATE_CHANGE (1<<8) /* Chipset power state changed */
+#define PD_EVENT_SEND_HARD_RESET (1<<9) /* Issue a Hard Reset. */
/* Ensure TCPC is out of low power mode before handling these events. */
#define PD_EXIT_LOW_POWER_EVENT_MASK \
@@ -1769,6 +1770,14 @@ int pd_get_polarity(int port);
int pd_get_partner_data_swap_capable(int port);
/**
+ * Handle an overcurrent protection event. The port acting as a source has
+ * reported an overcurrent event.
+ *
+ * @param port: USB-C port number.
+ */
+void pd_handle_overcurrent(int port);
+
+/**
* Request power swap command to be issued
*
* @param port USB-C port number
diff --git a/include/usbc_ppc.h b/include/usbc_ppc.h
index 06c2ff3f2f..a502ebe91e 100644
--- a/include/usbc_ppc.h
+++ b/include/usbc_ppc.h
@@ -11,6 +11,18 @@
/* Common APIs for USB Type-C Power Path Controllers (PPC) */
+/*
+ * Number of times a port may overcurrent before we latch off the port until a
+ * physical disconnect is detected.
+ */
+#define PPC_OC_CNT_THRESH 3
+
+/*
+ * Number of seconds until a latched-off port is re-enabled for sourcing after
+ * detecting a physical disconnect.
+ */
+#define PPC_OC_COOLDOWN_DELAY_US (2 * SECOND)
+
struct ppc_drv {
/**
* Initialize the PPC.
@@ -127,6 +139,31 @@ extern struct ppc_config_t ppc_chips[];
extern unsigned int ppc_cnt;
/**
+ * Increment the overcurrent event counter.
+ *
+ * @param port: The Type-C port that has overcurrented.
+ * @return EC_SUCCESS on success, EC_ERROR_INVAL if non-existent port.
+ */
+int ppc_add_oc_event(int port);
+
+/**
+ * Clear the overcurrent event counter.
+ *
+ * @param port: The Type-C port's counter to clear.
+ * @return EC_SUCCESS on success, EC_ERROR_INVAL if non-existent port.
+ */
+int ppc_clear_oc_event_counter(int port);
+
+/**
+ * Discharge PD VBUS on src/sink disconnect & power role swap
+ *
+ * @param port: The Type-C port number.
+ * @param enable: 1 -> discharge vbus, 0 -> stop discharging vbus
+ * @return EC_SUCCESS on success, error otherwise.
+ */
+int ppc_discharge_vbus(int port, int enable);
+
+/**
* Initializes the PPC for the specified port.
*
* @param port: The Type-C port number.
@@ -135,12 +172,12 @@ extern unsigned int ppc_cnt;
int ppc_init(int port);
/**
- * Determine if VBUS is present or not.
+ * Is the port latched off due to multiple overcurrent events in succession?
*
* @param port: The Type-C port number.
- * @return 1 if VBUS is present, 0 if not.
+ * @return 1 if the port is latched off, 0 if it is not latched off.
*/
-int ppc_is_vbus_present(int port);
+int ppc_is_port_latched_off(int port);
/**
* Is the port sourcing Vbus?
@@ -151,6 +188,25 @@ int ppc_is_vbus_present(int port);
int ppc_is_sourcing_vbus(int port);
/**
+ * Determine if VBUS is present or not.
+ *
+ * @param port: The Type-C port number.
+ * @return 1 if VBUS is present, 0 if not.
+ */
+int ppc_is_vbus_present(int port);
+
+/**
+ * Inform the PPC module that a sink is connected.
+ *
+ * This is used such that it can determine when to clear the overcurrent events
+ * counter for a port.
+ * @param port: The Type-C port number.
+ * @param is_connected: 1: if sink is connected on this port, 0: if not
+ * connected.
+ */
+void ppc_sink_is_connected(int port, int is_connected);
+
+/**
* Inform the PPC of the polarity of the CC pins.
*
* @param port: The Type-C port number.
@@ -177,15 +233,6 @@ int ppc_set_vbus_source_current_limit(int port, enum tcpc_rp_value rp);
int ppc_set_vconn(int port, int enable);
/**
- * Discharge PD VBUS on src/sink disconnect & power role swap
- *
- * @param port: The Type-C port number.
- * @param enable: 1 -> discharge vbus, 0 -> stop discharging vbus
- * @return EC_SUCCESS on success, error otherwise.
- */
-int ppc_discharge_vbus(int port, int enable);
-
-/**
* Turn on/off the charge path FET, such that current flows into the
* system.
*
@@ -209,8 +256,9 @@ int ppc_vbus_source_enable(int port, int enable);
* Board specific callback when a port overcurrents.
*
* @param port: The Type-C port which overcurrented.
+ * @param is_overcurrented: 1 if port overcurrented, 0 if the condition is gone.
*/
-void board_overcurrent_event(int port);
+void board_overcurrent_event(int port, int is_overcurrented);
/**
* Put the PPC into its lowest power state. In this state it should still fire