mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-11 18:35:28 +00:00
tcpc: move tcpc initialized bit into error status register
Move TCPC initialized bit from alert register into error status register. This is not part of the TCPCI spec, but the existing code creates a bug that if TCPM reboots without TCPC also rebooting, then we will never get the initialized alert from TCPC since it has already happened, so the TCPM will loop indefinitely waiting for TCPC to be ready. This fixes the bug by moving the bit to a status register, which is more appropriate. BUG=none BRANCH=none TEST=load on glados, reboot and make sure TCPM see's that the TCPC is initialized. Change-Id: I8e96b59031e01a4faec8f519727df1fa95f498bc Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/288342 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
b339fdf6c1
commit
e85a3fa0d4
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user