From ab212b5a417e57fb452f3962a9a00d3bbda7345e Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Thu, 21 Jun 2018 14:04:42 -0700 Subject: nocturne: Support new base USB fault protection IC. There is a new protection IC being introduced that will indicate a fault on the data lines. This commit adds support for that new fault pin which will follow the same behaviour as the other base power fault pin. The EC should disable pogo power when this goes off. BUG=b:110204244 BRANCH=None TEST=make -j BOARD=nocturne Change-Id: Ia29bbe7109abf22a372e4d50870d870b8bbde4c7 Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/1110940 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Furquan Shaikh --- board/nocturne/base_detect.c | 21 +++++++++++++++++---- board/nocturne/gpio.inc | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/board/nocturne/base_detect.c b/board/nocturne/base_detect.c index 188d9fecd0..4758448acd 100644 --- a/board/nocturne/base_detect.c +++ b/board/nocturne/base_detect.c @@ -58,6 +58,18 @@ enum base_detect_state { static int debug; static enum base_detect_state state; +static void enable_base_interrupts(int enable) +{ + int (*fn)(enum gpio_signal) = enable ? gpio_enable_interrupt : + gpio_disable_interrupt; + + /* This pin is present on boards newer than rev 0. */ + if (board_get_version() > 0) + fn(GPIO_BASE_USB_FAULT_ODL); + + fn(GPIO_BASE_PWR_FAULT_ODL); +} + static void base_power_enable(int enable) { /* Nothing to do if the state is the same. */ @@ -72,14 +84,14 @@ static void base_power_enable(int enable) /* Allow time for the fault line to rise. */ msleep(1); /* Monitor for base power faults. */ - gpio_enable_interrupt(GPIO_BASE_PWR_FAULT_ODL); + enable_base_interrupts(1); } } else { /* * Disable power fault interrupt. It will read low when base * power is removed. */ - gpio_disable_interrupt(GPIO_BASE_PWR_FAULT_ODL); + enable_base_interrupts(0); /* Now, remove power to the base. */ gpio_set_level(GPIO_BASE_PWR_EN, 0); } @@ -256,9 +268,10 @@ DECLARE_DEFERRED(check_and_reapply_base_power_deferred); void base_pwr_fault_interrupt(enum gpio_signal s) { /* Inverted because active low. */ - int fault_detected = !gpio_get_level(GPIO_BASE_PWR_FAULT_ODL); + int pwr_fault_detected = !gpio_get_level(GPIO_BASE_PWR_FAULT_ODL); + int usb_fault_detected = s == GPIO_BASE_USB_FAULT_ODL; - if (fault_detected) { + if (pwr_fault_detected | usb_fault_detected) { /* Turn off base power. */ CPRINTS("Base Pwr Flt!"); base_power_enable(0); diff --git a/board/nocturne/gpio.inc b/board/nocturne/gpio.inc index 5dfb36ffd9..4099a390b9 100644 --- a/board/nocturne/gpio.inc +++ b/board/nocturne/gpio.inc @@ -31,6 +31,7 @@ GPIO_INT(H1_EC_VOL_UP_ODL, PIN(7, 5), GPIO_INT_BOTH | GPIO_PULL_UP, button_int GPIO_INT(EC_WP_L, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt) GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, lid_interrupt) GPIO_INT(ACCELGYRO3_INT_L, PIN(4, 1), GPIO_INT_FALLING, bmi160_interrupt) +GPIO_INT(BASE_USB_FAULT_ODL, PIN(2, 3), GPIO_INT_FALLING, base_pwr_fault_interrupt) GPIO_INT(BASE_PWR_FAULT_ODL, PIN(2, 4), GPIO_INT_FALLING, base_pwr_fault_interrupt) GPIO_INT(RCAM_VSYNC, PIN(E, 4), GPIO_INT_FALLING, sync_interrupt) -- cgit v1.2.1