mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
pd: Add support for multiple distinct TCPC alert signals
If multiple TCPCs are present on a system then we may have multiple alert signals, each of which alerts us to the status of a different TCPC. Make boards with external non cros-ec TCPCs define tcpc_get_alert_status, which returns alert status based upon any alert GPIOs present, and then service only ports which are alerting. BUG=chromium:551683,chrome-os-partner:47851 TEST=Verify snoball PDCMD task sleeps appropriately when no devices are inserted, and verify ports go to PD_DISCOVERY state when we attach samus. Also verify that glados / glados_pd can still negotiate PD. BRANCH=None Change-Id: Iae6c4e1ef4d6685cb5bf7feef713505925a07c8c Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313209 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
9665d0b1df
commit
767e132d13
@@ -61,3 +61,17 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
|
||||
{I2C_PORT_TCPC, TCPC2_I2C_ADDR},
|
||||
#endif
|
||||
};
|
||||
|
||||
uint16_t tcpc_get_alert_status(void)
|
||||
{
|
||||
uint16_t status = 0;
|
||||
|
||||
if (!gpio_get_level(GPIO_PD_MCU_INT)) {
|
||||
status = PD_STATUS_TCPC_ALERT_0;
|
||||
#if CONFIG_USB_PD_PORT_COUNT >= 2
|
||||
status |= PD_STATUS_TCPC_ALERT_1;
|
||||
#endif
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,20 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
|
||||
{STM32_I2C2_PORT, FUSB302_I2C_SLAVE_ADDR + 2},
|
||||
};
|
||||
|
||||
uint16_t tcpc_get_alert_status(void)
|
||||
{
|
||||
uint16_t status = 0;
|
||||
|
||||
if (!gpio_get_level(GPIO_TCPC1_INT))
|
||||
status |= PD_STATUS_TCPC_ALERT_0;
|
||||
if (!gpio_get_level(GPIO_TCPC2_INT))
|
||||
status |= PD_STATUS_TCPC_ALERT_1;
|
||||
if (!gpio_get_level(GPIO_TCPC3_INT))
|
||||
status |= PD_STATUS_TCPC_ALERT_2;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/* ADC channels */
|
||||
const struct adc_t adc_channels[] = {
|
||||
/* Current sensing. Converted to mA (6600mV/4096). */
|
||||
|
||||
@@ -39,8 +39,6 @@ GPIO(OPTO_OUT, PIN(A, 8), GPIO_OUT_LOW)
|
||||
/* Unimplemented signals which we need to emulate for now */
|
||||
UNIMPLEMENTED(ENTERING_RW)
|
||||
UNIMPLEMENTED(WP_L)
|
||||
/* TODO(crbug.com/551683): Add support for multiple alert GPIOs */
|
||||
UNIMPLEMENTED(PD_MCU_INT)
|
||||
|
||||
/* Alternate functions */
|
||||
#if 0
|
||||
|
||||
@@ -133,16 +133,25 @@ static void pd_check_chg_status(struct ec_response_pd_status *pd_status)
|
||||
#endif /* CONFIG_HOSTCMD_PD */
|
||||
|
||||
#ifdef USB_TCPM_WITH_OFF_CHIP_TCPC
|
||||
static void pd_check_tcpc_alert(struct ec_response_pd_status *pd_status)
|
||||
static void pd_service_tcpc_ports(uint16_t port_status)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) {
|
||||
if (!pd_status ||
|
||||
(pd_status->status & (PD_STATUS_TCPC_ALERT_0 << i)))
|
||||
if (port_status & (PD_STATUS_TCPC_ALERT_0 << i))
|
||||
tcpc_alert(i);
|
||||
}
|
||||
}
|
||||
|
||||
static int pd_get_alert(void)
|
||||
{
|
||||
#ifdef CONFIG_HOSTCMD_PD
|
||||
return !gpio_get_level(GPIO_PD_MCU_INT);
|
||||
#else
|
||||
return !!tcpc_get_alert_status();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* USB_TCPM_WITH_OFF_CHIP_TCPC */
|
||||
|
||||
static void pd_exchange_status(uint32_t ec_state)
|
||||
@@ -179,16 +188,15 @@ static void pd_exchange_status(uint32_t ec_state)
|
||||
|
||||
#ifdef USB_TCPM_WITH_OFF_CHIP_TCPC
|
||||
#ifdef CONFIG_HOSTCMD_PD
|
||||
pd_check_tcpc_alert(&pd_status);
|
||||
pd_service_tcpc_ports(pd_status.status);
|
||||
#else
|
||||
pd_check_tcpc_alert(NULL);
|
||||
pd_service_tcpc_ports(tcpc_get_alert_status());
|
||||
#endif
|
||||
|
||||
if (!first_exchange) {
|
||||
if (!first_exchange)
|
||||
usleep(50*MSEC);
|
||||
first_exchange = 0;
|
||||
}
|
||||
} while (!gpio_get_level(GPIO_PD_MCU_INT));
|
||||
first_exchange = 0;
|
||||
} while (pd_get_alert());
|
||||
#endif /* USB_TCPM_WITH_OFF_CHIP_TCPC */
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,14 @@ struct tcpc_config_t {
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the PD_STATUS_TCPC_ALERT_* mask corresponding to the TCPC ports
|
||||
* that are currently asserting ALERT.
|
||||
*
|
||||
* @return PD_STATUS_TCPC_ALERT_* mask.
|
||||
*/
|
||||
uint16_t tcpc_get_alert_status(void);
|
||||
|
||||
/**
|
||||
* Initialize TCPM driver and wait for TCPC readiness.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user