mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 08:31:52 +00:00
oak_pd: tcpm_power_status: Update power status on init
Oak board relies on TCPCI power status. When board init, PD should update it's VBUS status and TCPM needs to get power status after enable TCPC power status mask. BRANCH=none BUG=chrome-os-partner:44952 TEST=manual build and load on oak, disconnect battery. power on system with zinger, and check PD state. Signed-off-by: Rong Chang <rongchang@chromium.org> Change-Id: Ic0d4b50d38ac39ff31b3a257c4b3b5dde0ebda4b Reviewed-on: https://chromium-review.googlesource.com/297871 Reviewed-by: Alec Berg <alecaberg@chromium.org>
This commit is contained in:
@@ -744,25 +744,6 @@ static void alert(int port, int mask)
|
||||
tcpc_alert(port);
|
||||
}
|
||||
|
||||
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 :
|
||||
TYPEC_CC_RD;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
int cc, i, res;
|
||||
@@ -1037,6 +1018,34 @@ int tcpc_get_message(int port, uint32_t *payload, int *head)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
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 :
|
||||
TYPEC_CC_RD;
|
||||
|
||||
/* 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));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_PD_TCPM_VBUS
|
||||
#if CONFIG_USB_PD_PORT_COUNT >= 2
|
||||
tcpc_set_power_status(port, !gpio_get_level(port ?
|
||||
GPIO_USB_C1_VBUS_WAKE_L :
|
||||
GPIO_USB_C0_VBUS_WAKE_L));
|
||||
#else
|
||||
tcpc_set_power_status(port, !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
|
||||
#endif /* CONFIG_USB_PD_PORT_COUNT >= 2 */
|
||||
#endif /* CONFIG_USB_PD_TCPM_VBUS */
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_PD_TCPM_VBUS
|
||||
void pd_vbus_evt_p0(enum gpio_signal signal)
|
||||
|
||||
@@ -55,31 +55,6 @@ static int init_power_status_mask(int port)
|
||||
}
|
||||
#endif
|
||||
|
||||
int tcpm_init(int port)
|
||||
{
|
||||
int rv, err = 0;
|
||||
|
||||
while (1) {
|
||||
rv = i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
|
||||
TCPC_REG_ERROR_STATUS, &err);
|
||||
/*
|
||||
* 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 && !(err & TCPC_REG_ERROR_STATUS_UNINIT)) {
|
||||
i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
|
||||
TCPC_REG_ALERT, 0xff);
|
||||
#ifdef CONFIG_USB_PD_TCPM_VBUS
|
||||
/* Initialize power_status_mask */
|
||||
init_power_status_mask(port);
|
||||
#endif
|
||||
return init_alert_mask(port);
|
||||
}
|
||||
msleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
int tcpm_get_cc(int port, int *cc1, int *cc2)
|
||||
{
|
||||
int status;
|
||||
@@ -294,3 +269,36 @@ void tcpc_alert(int port)
|
||||
TCPC_TX_COMPLETE_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
int tcpm_init(int port)
|
||||
{
|
||||
int rv, err = 0;
|
||||
#ifdef CONFIG_USB_PD_TCPM_VBUS
|
||||
int power_status;
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
rv = i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
|
||||
TCPC_REG_ERROR_STATUS, &err);
|
||||
/*
|
||||
* 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 && !(err & TCPC_REG_ERROR_STATUS_UNINIT)) {
|
||||
i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
|
||||
TCPC_REG_ALERT, 0xff);
|
||||
#ifdef CONFIG_USB_PD_TCPM_VBUS
|
||||
/* Initialize power_status_mask */
|
||||
init_power_status_mask(port);
|
||||
/* Read Power Status register */
|
||||
tcpm_get_power_status(port, &power_status);
|
||||
/* Update VBUS status */
|
||||
tcpc_vbus[port] = power_status &
|
||||
TCPC_REG_POWER_VBUS_PRES ? 1 : 0;
|
||||
#endif
|
||||
return init_alert_mask(port);
|
||||
}
|
||||
msleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user