From 75c0d2a6dc65603b9a9aff21f923d4432087bd0f Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Tue, 22 Dec 2020 15:30:31 -0800 Subject: sasuke: Rerun USB-C interrupts if still asserted This commit revises the USB-C interrupt handlers. Sometimes the interrupt line can remain asserted once we've finished handling the interrupt. This commit leverages the work that was done for the other dedede boards to check if the interrupt is still asserted and rerun the interrupt handlers if needed. BUG=b:143166332 BRANCH=dedede TEST=`make -j BOARD=sasuke` Signed-off-by: Aseda Aboagye Change-Id: Ia3fcd1f38e6de10259276d171128fb5dfa967f47 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2601173 Tested-by: Aseda Aboagye Reviewed-by: Diana Z Commit-Queue: Aseda Aboagye Auto-Submit: Aseda Aboagye --- board/sasuke/board.c | 72 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/board/sasuke/board.c b/board/sasuke/board.c index 138926c936..fad4b305bb 100644 --- a/board/sasuke/board.c +++ b/board/sasuke/board.c @@ -41,33 +41,81 @@ #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) #define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) -static void tcpc_alert_event(enum gpio_signal s) -{ - int port = (s == GPIO_USB_C0_INT_ODL) ? 0 : 1; +#define INT_RECHECK_US 5000 - schedule_deferred_pd_interrupt(port); -} +/* C0 interrupt line shared by BC 1.2 and charger */ +static void check_c0_line(void); +DECLARE_DEFERRED(check_c0_line); -static void usb_c0_interrupt(enum gpio_signal s) +static void notify_c0_chips(void) { /* * The interrupt line is shared between the TCPC and BC 1.2 detection * chip. Therefore we'll need to check both ICs. */ - tcpc_alert_event(s); + schedule_deferred_pd_interrupt(0); task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12); } -static void sub_usb_c1_interrupt(enum gpio_signal s) +static void check_c0_line(void) { /* - * The interrupt line is shared between the TCPC and BC 1.2 detection - * chip. Therefore we'll need to check both ICs. + * If line is still being held low, see if there's more to process from + * one of the chips */ - tcpc_alert_event(s); + if (!gpio_get_level(GPIO_USB_C0_INT_ODL)) { + notify_c0_chips(); + hook_call_deferred(&check_c0_line_data, INT_RECHECK_US); + } +} + +static void usb_c0_interrupt(enum gpio_signal s) +{ + /* Cancel any previous calls to check the interrupt line */ + hook_call_deferred(&check_c0_line_data, -1); + + /* Notify all chips using this line that an interrupt came in */ + notify_c0_chips(); + + /* Check the line again in 5ms */ + hook_call_deferred(&check_c0_line_data, INT_RECHECK_US); + +} + +/* C1 interrupt line shared by BC 1.2, TCPC, and charger */ +static void check_c1_line(void); +DECLARE_DEFERRED(check_c1_line); + +static void notify_c1_chips(void) +{ + schedule_deferred_pd_interrupt(1); task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12); } +static void check_c1_line(void) +{ + /* + * If line is still being held low, see if there's more to process from + * one of the chips. + */ + if (!gpio_get_level(GPIO_SUB_C1_INT_EN_RAILS_ODL)) { + notify_c1_chips(); + hook_call_deferred(&check_c1_line_data, INT_RECHECK_US); + } +} + +static void sub_usb_c1_interrupt(enum gpio_signal s) +{ + /* Cancel any previous calls to check the interrupt line */ + hook_call_deferred(&check_c1_line_data, -1); + + /* Notify all chips using this line that an interrupt came in */ + notify_c1_chips(); + + /* Check the line again in 5ms */ + hook_call_deferred(&check_c1_line_data, INT_RECHECK_US); + +} static void sub_hdmi_hpd_interrupt(enum gpio_signal s) { int hdmi_hpd_odl = gpio_get_level(GPIO_EC_I2C_SUB_C1_SDA_HDMI_HPD_ODL); @@ -129,6 +177,7 @@ void board_init(void) int on; gpio_enable_interrupt(GPIO_USB_C0_INT_ODL); + check_c0_line(); if (get_cbi_fw_config_db() == DB_1A_HDMI) { /* Disable i2c on HDMI pins */ @@ -155,6 +204,7 @@ void board_init(void) /* Enable C1 interrupts */ gpio_enable_interrupt(GPIO_SUB_C1_INT_EN_RAILS_ODL); + check_c1_line(); } /* Turn on 5V if the system is on, otherwise turn it off. */ -- cgit v1.2.1