summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-06-13 17:20:18 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-06-15 01:09:24 -0700
commit1957187084451471e8ecbce77df38513b8998335 (patch)
tree04d2ab8e6b277a275061c014d9c3e4671b9a6dc7
parent43552fb3f596573e0c633ad20fb313c21ddb281f (diff)
downloadchrome-ec-1957187084451471e8ecbce77df38513b8998335.tar.gz
pd: tcpci: Don't wait forever for init() on i2c error
If i2c communication with the TCPC is failing after 300ms+ then it's likely going to fail forever, so return an error to allow the PD task to continue initialization. BUG=chrome-os-partner:53815 BRANCH=None TEST=Manual on reef. Disconnect TCPC, attach charger to other port, and verify charge manager correctly sets current limit based on detection. Change-Id: I2c12320971a77504292f75393791e609e34897b4 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/352501 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--common/usb_pd_protocol.c10
-rw-r--r--driver/tcpm/tcpci.c10
2 files changed, 15 insertions, 5 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 75c38b1d08..a13b295503 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -54,6 +54,7 @@ static uint8_t pd_comm_enabled = 1;
#endif
#else /* CONFIG_COMMON_RUNTIME */
#define CPRINTF(format, args...)
+#define CPRINTS(format, args...)
static const int debug_level;
static const uint8_t pd_comm_enabled = 1;
#endif
@@ -1420,8 +1421,8 @@ void pd_task(void)
#endif
/* Initialize TCPM driver and wait for TCPC to be ready */
- tcpm_init(port);
- CPRINTF("[%T TCPC p%d ready]\n", port);
+ res = tcpm_init(port);
+ CPRINTS("TCPC p%d init %s", port, res ? "failed" : "ready");
/* Disable TCPC RX until connection is established */
tcpm_set_rx_enable(port, 0);
@@ -1475,8 +1476,9 @@ void pd_task(void)
#else
/* if TCPC has reset, then need to initialize it again */
if (evt & PD_EVENT_TCPC_RESET) {
- CPRINTF("[%T TCPC p%d reset!]\n", port);
- tcpm_init(port);
+ CPRINTS("TCPC p%d reset!", port);
+ if (tcpm_init(port) != EC_SUCCESS)
+ CPRINTS("TCPC p%d init failed", port);
/* Ensure CC termination is default */
tcpm_set_cc(port, PD_ROLE_DEFAULT == PD_ROLE_SOURCE ?
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 9a32dd5e19..4f8f96020d 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -250,10 +250,17 @@ void tcpci_tcpc_alert(int port)
}
}
+/*
+ * On TCPC i2c failure, make 30 tries (at least 300ms) before giving up
+ * in order to allow the TCPC time to boot / reset.
+ */
+#define TCPM_INIT_TRIES 30
+
int tcpci_tcpm_init(int port)
{
int rv;
int power_status;
+ int tries = TCPM_INIT_TRIES;
while (1) {
rv = tcpc_read(port, TCPC_REG_POWER_STATUS, &power_status);
@@ -271,7 +278,8 @@ int tcpci_tcpm_init(int port)
tcpc_vbus[port] = power_status &
TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0;
return init_alert_mask(port);
- }
+ } else if (rv != EC_SUCCESS && --tries == 0)
+ return rv;
msleep(10);
}
}