From 767e132d133b6f1216d630bd3b59e893a59bcffa Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Thu, 19 Nov 2015 16:51:37 -0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/313209 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Alec Berg --- common/host_command_pd.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'common/host_command_pd.c') diff --git a/common/host_command_pd.c b/common/host_command_pd.c index 477b602796..70178bf933 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -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 */ } -- cgit v1.2.1