From 7fb0338cbd40d40db2a304cd3e8ed10ae4f59450 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 1 Mar 2017 15:10:39 +0800 Subject: [PATCH] hammer: Pulse detection pin on USB wake event When usb_wake is called (key press, trackpad event), pulse detection pin for 100us. This allows Lid EC to wake the AP even when it is in deep S3 mode, where normal wake using USB lines does not work. BRANCH=none BUG=b:35775062 TEST=Flash hammer, looks at poppy console: base power is not disconnected, but events appear in the console. Change-Id: I7b8ee407046d4caa1ce75190c30d693b71b00d2e Reviewed-on: https://chromium-review.googlesource.com/448380 Commit-Ready: Nicolas Boichat Tested-by: Nicolas Boichat Reviewed-by: Vincent Palatin --- board/hammer/board.c | 21 +++++++++++++++++++++ board/hammer/gpio.inc | 2 ++ chip/stm32/usb.c | 9 +++++++++ include/usb_api.h | 3 +++ 4 files changed, 35 insertions(+) diff --git a/board/hammer/board.c b/board/hammer/board.c index c51dfdba81..4f157ad22c 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -15,6 +15,7 @@ #include "pwm_chip.h" #include "registers.h" #include "task.h" +#include "timer.h" #include "update_fw.h" #include "usart-stm32f0.h" #include "usart_tx_dma.h" @@ -85,3 +86,23 @@ void board_config_pre_init(void) */ STM32_SYSCFG_CFGR1 |= (1 << 9) | (1 << 10); /* Remap USART1 RX/TX DMA */ } + +/* + * Side-band USB wake, to be able to wake lid even in deep S3, when USB + * controller is off. + */ +void board_usb_wake(void) +{ + /* + * Poke detection pin for less than 100us, we disable interrupts + * to make sure that we do not get preempted (setting GPIO high + * for too long would prevent pulse detection on lid EC side from + * working properly, or even kill hammer power if it is held for + * longer than debounce time). + */ + interrupt_disable(); + gpio_set_flags(GPIO_BASE_DET, GPIO_OUT_HIGH); + udelay(100); + gpio_set_flags(GPIO_BASE_DET, GPIO_INPUT); + interrupt_enable(); +} diff --git a/board/hammer/gpio.inc b/board/hammer/gpio.inc index 6ab26af4ec..97befce89d 100644 --- a/board/hammer/gpio.inc +++ b/board/hammer/gpio.inc @@ -49,6 +49,8 @@ GPIO(KEYBOARD_BACKLIGHT, PIN(B, 9), GPIO_OUT_LOW) GPIO(WP_L, PIN(A, 13), GPIO_INPUT) +GPIO(BASE_DET, PIN(A, 15), GPIO_INPUT) + /* Unimplemented signals since we are not an EC */ UNIMPLEMENTED(ENTERING_RW) diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index b20f7d271f..018a26ce03 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -372,6 +372,12 @@ static volatile int usb_wake_done = 1; */ static volatile int esof_count; +__attribute__((weak)) +void board_usb_wake(void) +{ + /* Side-band USB wake, do nothing by default. */ +} + void usb_wake(void) { if (!remote_wakeup_enabled || @@ -396,6 +402,9 @@ void usb_wake(void) */ esof_count = 3; STM32_USB_CNTR |= STM32_USB_CNTR_RESUME | STM32_USB_CNTR_ESOFM; + + /* Try side-band wake as well. */ + board_usb_wake(); } #endif diff --git a/include/usb_api.h b/include/usb_api.h index c6a949ab61..4803890504 100644 --- a/include/usb_api.h +++ b/include/usb_api.h @@ -56,6 +56,9 @@ int usb_is_suspended(void); */ void usb_wake(void); +/* Board-specific USB wake, for side-band wake, called by usb_wake above. */ +void board_usb_wake(void); + #ifdef CONFIG_USB_SELECT_PHY /* Select which PHY to use. */ void usb_select_phy(uint32_t phy);