diff --git a/board/pdeval-stm32f072/board.c b/board/pdeval-stm32f072/board.c index 6fd472eee5..ab476d006e 100644 --- a/board/pdeval-stm32f072/board.c +++ b/board/pdeval-stm32f072/board.c @@ -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; +} diff --git a/board/snoball/board.c b/board/snoball/board.c index a081bab8c3..d4d05f13ea 100644 --- a/board/snoball/board.c +++ b/board/snoball/board.c @@ -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). */ diff --git a/board/snoball/gpio.inc b/board/snoball/gpio.inc index 776d42934c..cd0b71825e 100644 --- a/board/snoball/gpio.inc +++ b/board/snoball/gpio.inc @@ -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 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 */ } diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 6b1180cafd..4e1b04249e 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -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. *