diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c index 272b44e652..eb0b47b3c5 100644 --- a/common/usb_pd_tcpc.c +++ b/common/usb_pd_tcpc.c @@ -195,6 +195,8 @@ enum pd_tx_errors { PD_TX_ERR_COLLISION = -5 /* Collision detected during transmit */ }; +#define TCPC_FLAGS_INITIALIZED (1 << 0) /* TCPC is initialized */ + static struct pd_port_controller { /* current port power role (SOURCE or SINK) */ uint8_t power_role; @@ -211,6 +213,8 @@ static struct pd_port_controller { uint16_t alert_mask; /* RX enabled */ uint8_t rx_enabled; + /* TCPC flags */ + uint8_t flags; /* Last received */ int rx_head; @@ -811,7 +815,7 @@ void pd_task(void) tcpc_init(port); /* we are now initialized */ - alert(port, TCPC_REG_ALERT_TCPC_INITED); + pd[port].flags |= TCPC_FLAGS_INITIALIZED; while (1) { /* wait for next event/packet or timeout expiration */ @@ -1005,6 +1009,10 @@ static int tcpc_i2c_read(int port, int reg, uint8_t *payload) case TCPC_REG_VENDOR_ID: *(uint16_t *)payload = USB_VID_GOOGLE; return 2; + case TCPC_REG_ERROR_STATUS: + payload[0] = (pd[port].flags & TCPC_FLAGS_INITIALIZED) ? + 0 : TCPC_REG_ERROR_STATUS_UNINIT; + return 1; case TCPC_REG_CC_STATUS: tcpc_get_cc(port, &cc1, &cc2); payload[0] = TCPC_REG_CC_STATUS_SET( diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index cd5c783db8..8353cb15d9 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -39,17 +39,17 @@ static int init_alert_mask(int port) int tcpm_init(int port) { - int rv, alert = 0; + int rv, err = 0; while (1) { rv = i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), - TCPC_REG_ALERT, &alert); + TCPC_REG_ERROR_STATUS, &err); /* - * If i2c succeeds and VID is non-zero, then initialization - * is complete + * If i2c succeeds and the uninitialized bit is clear, then + * initalization is complete, clear all alert bits and write + * the initial alert mask. */ - if (rv == EC_SUCCESS && (alert & TCPC_REG_ALERT_TCPC_INITED)) { - /* clear all alert bits */ + if (rv == EC_SUCCESS && !(err & TCPC_REG_ERROR_STATUS_UNINIT)) { i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), TCPC_REG_ALERT, 0xff); return init_alert_mask(port); diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h index a4ee23bc0a..18f9a75e95 100644 --- a/driver/tcpm/tcpci.h +++ b/driver/tcpm/tcpci.h @@ -19,7 +19,6 @@ #define TCPC_REG_DEV_CAP_3 0xe #define TCPC_REG_DEV_CAP_4 0xf #define TCPC_REG_ALERT 0x10 -#define TCPC_REG_ALERT_TCPC_INITED (1<<14) #define TCPC_REG_ALERT_INTRFACE_ERR (1<<11) #define TCPC_REG_ALERT_GPIO_CHANGE (1<<10) #define TCPC_REG_ALERT_V_ALARM_LO (1<<9) @@ -47,6 +46,7 @@ #define TCPC_REG_POWER_STATUS 0x19 #define TCPC_REG_ERROR_STATUS 0x1a +#define TCPC_REG_ERROR_STATUS_UNINIT (1<<7) #define TCPC_REG_ROLE_CTRL 0x1b #define TCPC_REG_ROLE_CTRL_SET(drp, rp, cc1, cc2) \ ((drp) << 6 | (rp) << 4 | (cc2) << 2 | (cc1))