summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-06-29 15:51:33 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-30 19:02:57 +0000
commita11ffa6c93e28f536cf97eb29e613399d25baf63 (patch)
treeae334ab1abad2577eafffb6f7216dfd3878ab78d
parentdd9e4fa427d106a716534cf85da4c27a0e932957 (diff)
downloadchrome-ec-a11ffa6c93e28f536cf97eb29e613399d25baf63.tar.gz
tcpc: use initialization complete alert bit to signal readiness
Use the new TCPC initialization complete bit in alert register to signal TCPC readiness instead of checking for USB VID to be set. BUG=none BRANCH=none TEST=load on glados, make sure we can boot without battery. Change-Id: I4b25c973ece0de6dd3f419c5901cff1d8d05ed95 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/282593 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--common/usb_pd_tcpc.c19
-rw-r--r--driver/tcpm/tcpci.c10
2 files changed, 19 insertions, 10 deletions
diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c
index 54e3ceeca7..272b44e652 100644
--- a/common/usb_pd_tcpc.c
+++ b/common/usb_pd_tcpc.c
@@ -41,9 +41,6 @@ static struct mutex pd_crc_lock;
static const int debug_level;
#endif
-/* USB Vendor ID, initialized to 0, written to actual VID when TCPC is ready */
-static int tcpc_vid;
-
/* Encode 5 bits using Biphase Mark Coding */
#define BMC(x) ((x & 1 ? 0x001 : 0x3FF) \
^ (x & 2 ? 0x004 : 0x3FC) \
@@ -712,6 +709,8 @@ static void alert(int port, int mask)
void tcpc_init(int port)
{
+ int i;
+
/* Initialize physical layer */
pd_hw_init(port, PD_ROLE_DEFAULT);
pd[port].cc_pull = PD_ROLE_DEFAULT == PD_ROLE_SOURCE ? TYPEC_CC_RP :
@@ -719,6 +718,12 @@ void tcpc_init(int port)
/* make sure PD monitoring is disabled initially */
pd[port].rx_enabled = 0;
+
+ /* make initial readings of CC voltages */
+ for (i = 0; i < 2; i++) {
+ pd[port].cc_status[i] = cc_voltage_to_status(port,
+ pd_adc_read(port, i));
+ }
}
int tcpc_run(int port, int evt)
@@ -791,9 +796,6 @@ int tcpc_run(int port, int evt)
if (pd[port].rx_enabled)
pd_rx_enable_monitoring(port);
- /* write our TCPC VID to notify TCPM that we are ready */
- tcpc_vid = USB_VID_GOOGLE;
-
/* TODO: adjust timeout based on how often to sample CC */
return 10*MSEC;
}
@@ -808,6 +810,9 @@ void pd_task(void)
/* initialize phy task */
tcpc_init(port);
+ /* we are now initialized */
+ alert(port, TCPC_REG_ALERT_TCPC_INITED);
+
while (1) {
/* wait for next event/packet or timeout expiration */
evt = task_wait_event(timeout);
@@ -998,7 +1003,7 @@ static int tcpc_i2c_read(int port, int reg, uint8_t *payload)
switch (reg) {
case TCPC_REG_VENDOR_ID:
- *(uint16_t *)payload = tcpc_vid;
+ *(uint16_t *)payload = USB_VID_GOOGLE;
return 2;
case TCPC_REG_CC_STATUS:
tcpc_get_cc(port, &cc1, &cc2);
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index ecb68bbf53..cd5c783db8 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -39,17 +39,21 @@ static int init_alert_mask(int port)
int tcpm_init(int port)
{
- int rv, vid = 0;
+ int rv, alert = 0;
while (1) {
rv = i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
- TCPC_REG_VENDOR_ID, &vid);
+ TCPC_REG_ALERT, &alert);
/*
* If i2c succeeds and VID is non-zero, then initialization
* is complete
*/
- if (rv == EC_SUCCESS && vid)
+ if (rv == EC_SUCCESS && (alert & TCPC_REG_ALERT_TCPC_INITED)) {
+ /* clear all alert bits */
+ i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
+ TCPC_REG_ALERT, 0xff);
return init_alert_mask(port);
+ }
msleep(10);
}
}