summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-12-10 10:24:12 -0700
committerCommit Bot <commit-bot@chromium.org>2019-12-12 03:53:55 +0000
commit896271dad5edbfaad2b0ff10a6fb1dcfb1143089 (patch)
tree01ae1278294b969fc70d0b6f15f963b2c2bc7e19 /driver
parent40b6c5de590e6290e6b516c380f6b59efbff4fa3 (diff)
downloadchrome-ec-896271dad5edbfaad2b0ff10a6fb1dcfb1143089.tar.gz
tcpci: change connect to auto discharge disconnect
It was originally thought the connect/disconnect would be a good generic way to set/clear auto_discharge_disconnect but it was not working reliably. Although the points that we are calling to perform this enable/disable are close to the connect/disconnect, there is more fine tuning required to make this work. BUG=b:144126745,chromium:951683 BRANCH=none TEST=attach/disconnect charger with and without AP running TEST=attach/disconnect device with AP running Change-Id: Ib1418771aec6d0a52895972e4db6881b072c0c3d Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1960514 Reviewed-by: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/tcpm/nct38xx.c4
-rw-r--r--driver/tcpm/stub.c4
-rw-r--r--driver/tcpm/tcpci.c34
-rw-r--r--driver/tcpm/tcpci.h3
-rw-r--r--driver/tcpm/tcpm.h16
5 files changed, 28 insertions, 33 deletions
diff --git a/driver/tcpm/nct38xx.c b/driver/tcpm/nct38xx.c
index b29c270d70..f4b9da3132 100644
--- a/driver/tcpm/nct38xx.c
+++ b/driver/tcpm/nct38xx.c
@@ -305,8 +305,8 @@ const struct tcpm_drv nct38xx_tcpm_drv = {
#ifdef CONFIG_USB_PD_DISCHARGE_TCPC
.tcpc_discharge_vbus = &tcpci_tcpc_discharge_vbus,
#endif
- .tcpc_connect_state_change =
- &tcpci_tcpc_connect_state_change,
+ .tcpc_enable_auto_discharge_disconnect =
+ &tcpci_tcpc_enable_auto_discharge_disconnect,
#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
.drp_toggle = &tcpci_nct38xx_drp_toggle,
#endif
diff --git a/driver/tcpm/stub.c b/driver/tcpm/stub.c
index 0ebe8af999..3626f148fc 100644
--- a/driver/tcpm/stub.c
+++ b/driver/tcpm/stub.c
@@ -89,6 +89,10 @@ int tcpm_set_rx_enable(int port, int enable)
return tcpc_set_rx_enable(port, enable);
}
+void tcpm_enable_auto_discharge_disconnect(int port, int enable)
+{
+}
+
int tcpm_has_pending_message(int port)
{
return !rx_buf_is_empty(port);
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 4194f19e6a..5d16de206a 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -10,7 +10,6 @@
#include "compile_time_macros.h"
#include "console.h"
#include "ec_commands.h"
-#include "hooks.h"
#include "ps8xxx.h"
#include "task.h"
#include "tcpci.h"
@@ -283,38 +282,17 @@ void tcpci_tcpc_discharge_vbus(int port, int enable)
}
/*
- * On a connection state change, it is necessary for TCPCI devices to
- * set the AUTO_DISCHARGE_DISCONNECT bit appropriately.
+ * Auto Discharge Disconnect is supposed to be enabled when we
+ * are connected and disabled after we are disconnected and
+ * VBus is at SafeV0
*/
-void tcpci_tcpc_connect_state_change(int port, int connected)
+void tcpci_tcpc_enable_auto_discharge_disconnect(int port, int enable)
{
tcpc_update8(port,
TCPC_REG_POWER_CTRL,
TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT,
- (connected) ? MASK_SET : MASK_CLR);
-}
-
-static void connect_state_change(int port, int connected)
-{
- const struct tcpm_drv *tcpc = tcpc_config[port].drv;
-
- if (tcpc->tcpc_connect_state_change)
- tcpc->tcpc_connect_state_change(port, connected);
-}
-static void connect_hook(void)
-{
- int port = TASK_ID_TO_PD_PORT(task_get_current());
-
- connect_state_change(port, 1);
-}
-DECLARE_HOOK(HOOK_USB_PD_CONNECT, connect_hook, HOOK_PRIO_DEFAULT);
-static void disconnect_hook(void)
-{
- int port = TASK_ID_TO_PD_PORT(task_get_current());
-
- connect_state_change(port, 0);
+ (enable) ? MASK_SET : MASK_CLR);
}
-DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, disconnect_hook, HOOK_PRIO_DEFAULT);
static int set_role_ctrl(int port, int toggle, int rp, int pull)
{
@@ -1146,8 +1124,6 @@ const struct tcpm_drv tcpci_tcpm_drv = {
#ifdef CONFIG_USB_PD_DISCHARGE_TCPC
.tcpc_discharge_vbus = &tcpci_tcpc_discharge_vbus,
#endif
- .tcpc_connect_state_change =
- &tcpci_tcpc_connect_state_change,
#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
.drp_toggle = &tcpci_tcpc_drp_toggle,
#endif
diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h
index 46e1d024aa..566e7905e9 100644
--- a/driver/tcpm/tcpci.h
+++ b/driver/tcpm/tcpci.h
@@ -182,8 +182,7 @@ int tcpci_enter_low_power_mode(int port);
#ifdef CONFIG_USB_PD_DISCHARGE_TCPC
void tcpci_tcpc_discharge_vbus(int port, int enable);
#endif
-
-void tcpci_tcpc_connect_state_change(int port, int connected);
+void tcpci_tcpc_enable_auto_discharge_disconnect(int port, int enable);
int tcpci_tcpm_mux_init(int i2c_addr);
int tcpci_tcpm_mux_set(int i2c_addr, mux_state_t mux_state);
diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h
index 7669135a31..118275ba3d 100644
--- a/driver/tcpm/tcpm.h
+++ b/driver/tcpm/tcpm.h
@@ -199,6 +199,14 @@ static inline int tcpm_set_rx_enable(int port, int enable)
return tcpc_config[port].drv->set_rx_enable(port, enable);
}
+static inline void tcpm_enable_auto_discharge_disconnect(int port, int enable)
+{
+ const struct tcpm_drv *tcpc = tcpc_config[port].drv;
+
+ if (tcpc->tcpc_enable_auto_discharge_disconnect)
+ tcpc->tcpc_enable_auto_discharge_disconnect(port, enable);
+}
+
/**
* Reads a message using get_message_raw driver method and puts it into EC's
* cache.
@@ -374,6 +382,14 @@ int tcpm_set_msg_header(int port, int power_role, int data_role);
int tcpm_set_rx_enable(int port, int enable);
/**
+ * Enable Auto Discharge Disconnect
+ *
+ * @param port Type-C port number
+ * @param enable true for enable, false for disable
+ */
+void tcpm_enable_auto_discharge_disconnect(int port, int enable);
+
+/**
* Transmit PD message
*
* @param port Type-C port number