summaryrefslogtreecommitdiff
path: root/common/usbc
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-10-30 14:18:56 -0600
committerCommit Bot <commit-bot@chromium.org>2020-11-18 03:57:56 +0000
commite1ba4c2931cdf5ca40d3121dcca5a77ccfaaa180 (patch)
treed28d5db09af798fd2972a4c4f902d770a951fe1a /common/usbc
parentdcdbd07041be46526ba9bb3529943d8f6c927119 (diff)
downloadchrome-ec-e1ba4c2931cdf5ca40d3121dcca5a77ccfaaa180.tar.gz
TCPM: Add OCP module
Currently, the overcurrent protection is tracked in the PPC code. However, as different chips are able to report overcurrent move this code into a generic module. Logic for not sourcing Vbus or Vconn on latched ports moves into the TC layer, and an overridable board overcurrent function is provided for boards which have no special actions to take. BRANCH=None BUG=b:171501161 TEST=make -j buildall; TCPMv2 tested with following drawcia patch Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I75919e345a5b0bce4a0b67432a13515e7716cf6a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2532676 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Signed-off-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2546416
Diffstat (limited to 'common/usbc')
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 2b1da47c79..fd334b6b12 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -19,6 +19,7 @@
#include "usb_prl_sm.h"
#include "usb_sm.h"
#include "usb_tc_sm.h"
+#include "usbc_ocp.h"
#include "usbc_ppc.h"
#include "vboot.h"
@@ -971,6 +972,15 @@ void tc_snk_power_off(int port)
int tc_src_power_on(int port)
{
+ /*
+ * Check our OC event counter. If we've exceeded our threshold, then
+ * let's latch our source path off to prevent continuous cycling. When
+ * the PD state machine detects a disconnection on the CC lines, we will
+ * reset our OC event counter.
+ */
+ if (IS_ENABLED(CONFIG_USBC_OCP) && usbc_ocp_is_port_latched_off(port))
+ return EC_ERROR_ACCESS_DENIED;
+
if (IS_ATTACHED_SRC(port))
return pd_set_power_supply_ready(port);
@@ -987,6 +997,23 @@ void tc_src_power_off(int port)
CHARGE_CEIL_NONE);
}
+/* Set what role the partner is right now, for the PPC and OCP module */
+static void tc_set_partner_role(int port, enum ppc_device_role role)
+{
+ if (IS_ENABLED(CONFIG_USBC_PPC))
+ ppc_dev_is_connected(port, role);
+
+ if (IS_ENABLED(CONFIG_USBC_OCP)) {
+ usbc_ocp_snk_is_connected(port, role == PPC_DEV_SNK);
+ /*
+ * Clear the overcurrent event counter
+ * since we've detected a disconnect.
+ */
+ if (role == PPC_DEV_DISCONNECTED)
+ usbc_ocp_clear_event_counter(port);
+ }
+}
+
/*
* Depending on the load on the processor and the tasks running
* it can take a while for the task associated with this port
@@ -1625,6 +1652,16 @@ static void set_vconn(int port, int enable)
TC_CLR_FLAG(port, TC_FLAGS_VCONN_ON);
/*
+ * Check our OC event counter. If we've exceeded our threshold, then
+ * let's latch our source path off to prevent continuous cycling. When
+ * the PD state machine detects a disconnection on the CC lines, we will
+ * reset our OC event counter.
+ */
+ if (IS_ENABLED(CONFIG_USBC_OCP) &&
+ enable && usbc_ocp_is_port_latched_off(port))
+ return;
+
+ /*
* Disable PPC Vconn first then TCPC in case the voltage feeds back
* to TCPC and damages.
*/
@@ -2010,16 +2047,7 @@ static void tc_unattached_snk_entry(const int port)
if (IS_ENABLED(CONFIG_CHARGE_MANAGER))
charge_manager_update_dualrole(port, CAP_UNKNOWN);
- if (IS_ENABLED(CONFIG_USBC_PPC)) {
- /* There is no source connected. */
- ppc_dev_is_connected(port, PPC_DEV_DISCONNECTED);
-
- /*
- * Clear the overcurrent event counter
- * since we've detected a disconnect.
- */
- ppc_clear_oc_event_counter(port);
- }
+ tc_set_partner_role(port, PPC_DEV_DISCONNECTED);
/*
* Indicate that the port is disconnected so the board
@@ -2215,9 +2243,8 @@ static void tc_attached_snk_entry(const int port)
*/
typec_select_pull(port, TYPEC_CC_RD);
- /* Inform PPC that a source is connected. */
- if (IS_ENABLED(CONFIG_USBC_PPC))
- ppc_dev_is_connected(port, PPC_DEV_SRC);
+ /* Inform the PPC and OCP module that a source is connected */
+ tc_set_partner_role(port, PPC_DEV_SRC);
if (IS_ENABLED(CONFIG_USB_PE_SM) &&
TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS)) {
@@ -2513,16 +2540,7 @@ static void tc_unattached_src_entry(const int port)
*/
bc12_role_change_handler(port, prev_data_role, tc[port].data_role);
- if (IS_ENABLED(CONFIG_USBC_PPC)) {
- /* There is no sink connected. */
- ppc_dev_is_connected(port, PPC_DEV_DISCONNECTED);
-
- /*
- * Clear the overcurrent event counter
- * since we've detected a disconnect.
- */
- ppc_clear_oc_event_counter(port);
- }
+ tc_set_partner_role(port, PPC_DEV_DISCONNECTED);
if (IS_ENABLED(CONFIG_CHARGE_MANAGER))
charge_manager_update_dualrole(port, CAP_UNKNOWN);
@@ -2548,12 +2566,12 @@ static void tc_unattached_src_run(const int port)
}
}
- if (IS_ENABLED(CONFIG_USBC_PPC)) {
+ if (IS_ENABLED(CONFIG_USBC_OCP)) {
/*
* If the port is latched off, just continue to
* monitor for a detach.
*/
- if (ppc_is_port_latched_off(port))
+ if (usbc_ocp_is_port_latched_off(port))
return;
}
@@ -2789,9 +2807,8 @@ static void tc_attached_src_entry(const int port)
typec_update_cc(port);
}
- /* Inform PPC that a sink is connected. */
- if (IS_ENABLED(CONFIG_USBC_PPC))
- ppc_dev_is_connected(port, PPC_DEV_SNK);
+ /* Inform PPC and OCP module that a sink is connected. */
+ tc_set_partner_role(port, PPC_DEV_SNK);
/*
* Only notify if we're not performing a power role swap. During a
@@ -3486,16 +3503,7 @@ static void tc_cc_open_entry(const int port)
typec_select_pull(port, TYPEC_CC_OPEN);
typec_update_cc(port);
- if (IS_ENABLED(CONFIG_USBC_PPC)) {
- /* There is no device connected. */
- ppc_dev_is_connected(port, PPC_DEV_DISCONNECTED);
-
- /*
- * Clear the overcurrent event counter
- * since we've detected a disconnect.
- */
- ppc_clear_oc_event_counter(port);
- }
+ tc_set_partner_role(port, PPC_DEV_DISCONNECTED);
}
void tc_set_debug_level(enum debug_level debug_level)