summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-10-20 15:37:11 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-10-22 17:40:31 -0700
commit7e81bebb48274055ace613796b9d1ede45c8c9d7 (patch)
tree2a02ef3b96049225f30369e82b2f2b9f007eda20 /driver
parent0f4e6d217d930c6f3b849f232b1260aed099f260 (diff)
downloadchrome-ec-7e81bebb48274055ace613796b9d1ede45c8c9d7.tar.gz
tcpc: re-initialize tcpc if it reboots while tcpm is running
On TCPC startup, set an alert to notify TCPM that we have been reset. When TCPM gets this notification, it should re-send initial TCPC parameters. If we were in a stable contract as a sink, make sure we don't reset connection. If not, then reset PD protocol state machine to the default state. This fixes a bug where if the TCPC reboots while the TCPM is still running, then the TCPC would not get re-initialized and therefore no PD communication would not work. This also fixes it such that if we are in a stable contract as a sink and the TCPC reboots, then we don't lose power. BUG=chrome-os-partner:46676 BRANCH=none TEST=tested on glados. reboot PD MCU with and without a charger plugged in and verify that PD communication works after the reboot. verify that with a charger, we don't lose power. also tested with a hoho plugged in during reboot. Change-Id: I84fec4577b0daf5891bd8461d3f3d925014a5ecf Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/307187 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/tcpm/stub.c13
-rw-r--r--driver/tcpm/tcpci.c39
-rw-r--r--driver/tcpm/tcpci.h2
3 files changed, 40 insertions, 14 deletions
diff --git a/driver/tcpm/stub.c b/driver/tcpm/stub.c
index 35f0329484..08c5f37a35 100644
--- a/driver/tcpm/stub.c
+++ b/driver/tcpm/stub.c
@@ -43,10 +43,21 @@ static int init_alert_mask(int port)
return rv;
}
+static int init_power_status_mask(int port)
+{
+ return tcpm_set_power_status_mask(port, 0);
+}
+
int tcpm_init(int port)
{
+ int rv;
+
tcpc_init(port);
- return init_alert_mask(port);
+ rv = init_alert_mask(port);
+ if (rv)
+ return rv;
+
+ return init_power_status_mask(port);
}
int tcpm_get_cc(int port, int *cc1, int *cc2)
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 149e7c9f5e..6d0a38f3c1 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -42,18 +42,20 @@ static int init_alert_mask(int port)
return rv;
}
-#ifdef CONFIG_USB_PD_TCPM_VBUS
static int init_power_status_mask(int port)
{
uint8_t mask;
int rv;
+#ifdef CONFIG_USB_PD_TCPM_VBUS
mask = TCPC_REG_POWER_STATUS_VBUS_PRES;
+#else
+ mask = 0;
+#endif
rv = tcpm_set_power_status_mask(port, mask);
return rv;
}
-#endif
int tcpm_get_cc(int port, int *cc1, int *cc2)
{
@@ -220,7 +222,6 @@ int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
void tcpc_alert(int port)
{
int status;
- int power_status;
/* Read the Alert register from the TCPC */
tcpm_alert_status(port, &status);
@@ -238,16 +239,30 @@ void tcpc_alert(int port)
task_set_event(PD_PORT_TO_TASK_ID(port), PD_EVENT_CC, 0);
}
if (status & TCPC_REG_ALERT_POWER_STATUS) {
- /* Read Power Status register */
- tcpm_get_power_status(port, &power_status);
- /* Update VBUS status */
- tcpc_vbus[port] = power_status &
- TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0;
+ int reg = 0;
+
+ i2c_read8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
+ TCPC_REG_POWER_STATUS_MASK, &reg);
+
+ if (reg == TCPC_REG_POWER_STATUS_MASK_ALL) {
+ /*
+ * If power status mask has been reset, then the TCPC
+ * has reset.
+ */
+ task_set_event(PD_PORT_TO_TASK_ID(port),
+ PD_EVENT_TCPC_RESET, 0);
+ } else {
+ /* Read Power Status register */
+ tcpm_get_power_status(port, &reg);
+ /* Update VBUS status */
+ tcpc_vbus[port] = reg &
+ TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0;
#if defined(CONFIG_USB_PD_TCPM_VBUS) && defined(CONFIG_USB_CHARGER)
- /* Update charge manager with new VBUS state */
- usb_charger_vbus_change(port, tcpc_vbus[port]);
+ /* Update charge manager with new VBUS state */
+ usb_charger_vbus_change(port, tcpc_vbus[port]);
#endif /* CONFIG_USB_PD_TCPM_VBUS && CONFIG_USB_CHARGER */
- task_wake(PD_PORT_TO_TASK_ID(port));
+ task_wake(PD_PORT_TO_TASK_ID(port));
+ }
}
if (status & TCPC_REG_ALERT_RX_STATUS) {
/* message received */
@@ -283,13 +298,11 @@ int tcpm_init(int port)
!(power_status & TCPC_REG_POWER_STATUS_UNINIT)) {
i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
TCPC_REG_ALERT, 0xffff);
-#ifdef CONFIG_USB_PD_TCPM_VBUS
/* Initialize power_status_mask */
init_power_status_mask(port);
/* Update VBUS status */
tcpc_vbus[port] = power_status &
TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0;
-#endif
return init_alert_mask(port);
}
msleep(10);
diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h
index da6e412669..d105ea5361 100644
--- a/driver/tcpm/tcpci.h
+++ b/driver/tcpm/tcpci.h
@@ -16,6 +16,7 @@
#define TCPC_REG_PD_INT_REV 0xa
#define TCPC_REG_ALERT 0x10
+#define TCPC_REG_ALERT_MASK_ALL 0xfff
#define TCPC_REG_ALERT_VBUS_DISCNCT (1<<11)
#define TCPC_REG_ALERT_RX_BUF_OVF (1<<10)
#define TCPC_REG_ALERT_FAULT (1<<9)
@@ -59,6 +60,7 @@
#define TCPC_REG_CC_STATUS_CC1(reg) ((reg) & 0x3)
#define TCPC_REG_POWER_STATUS 0x1e
+#define TCPC_REG_POWER_STATUS_MASK_ALL 0xff
#define TCPC_REG_POWER_STATUS_VBUS_PRES (1<<2)
#define TCPC_REG_POWER_STATUS_VBUS_DET (1<<3)
#define TCPC_REG_POWER_STATUS_UNINIT (1<<6)