diff options
author | Dominic Chen <ddchen@chromium.org> | 2014-06-06 14:46:00 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-07-02 00:45:29 +0000 |
commit | bab451bd7cdc71c5faff7f220ffc48e32da2e9ad (patch) | |
tree | 49d1e2d40582cc12f03af7585282f55faf71702a | |
parent | 73ad1f30c8ed14206ec9146d791773b5e64c0a3a (diff) | |
download | chrome-ec-bab451bd7cdc71c5faff7f220ffc48e32da2e9ad.tar.gz |
pd: add support for suspending the task
used by usb debug, which uses the same spi port
BRANCH=none
BUG=none
TEST=verify PD communication works after suspend with two fruitpies
Change-Id: I9d7e963fc27dc5303a8b87a9ddb68e97600a5a10
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202992
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | chip/stm32/usb_pd_phy.c | 8 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 21 | ||||
-rw-r--r-- | include/usb_pd.h | 11 |
3 files changed, 39 insertions, 1 deletions
diff --git a/chip/stm32/usb_pd_phy.c b/chip/stm32/usb_pd_phy.c index 895d5dab9d..b4fefa8fa4 100644 --- a/chip/stm32/usb_pd_phy.c +++ b/chip/stm32/usb_pd_phy.c @@ -394,6 +394,14 @@ void pd_rx_handler(void) DECLARE_IRQ(STM32_IRQ_COMP, pd_rx_handler, 1); #endif +/* --- release hardware --- */ +void pd_hw_release(void) +{ + __hw_timer_enable_clock(TIM_RX, 0); + __hw_timer_enable_clock(TIM_TX, 0); + dma_disable(DMAC_SPI_TX); +} + /* --- Startup initialization --- */ void *pd_hw_init(void) { diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 802ba46843..de5dfcf0c1 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -197,6 +197,7 @@ static uint8_t pd_polarity; static enum { PD_STATE_DISABLED, #ifdef CONFIG_USB_PD_DUAL_ROLE + PD_STATE_SUSPENDED, PD_STATE_SNK_DISCONNECTED, PD_STATE_SNK_DISCOVERY, PD_STATE_SNK_REQUESTED, @@ -870,6 +871,17 @@ void pd_task(void) } break; #ifdef CONFIG_USB_PD_DUAL_ROLE + case PD_STATE_SUSPENDED: + pd_rx_disable_monitoring(); + pd_hw_release(); + pd_power_supply_reset(); + + /* Wait for resume */ + while (pd_task_state == PD_STATE_SUSPENDED) + task_wait_event(-1); + + pd_hw_init(); + break; case PD_STATE_SNK_DISCONNECTED: /* Source connection monitoring */ #ifdef BOARD_SAMUS_PD @@ -973,6 +985,13 @@ void pd_rx_event(void) } #ifdef CONFIG_COMMON_RUNTIME +void pd_set_suspend(int enable) +{ + pd_task_state = enable ? PD_STATE_SUSPENDED : PD_DEFAULT_STATE; + + task_wake(TASK_ID_PD); +} + void pd_request_source_voltage(int mv) { pd_set_max_voltage(mv); @@ -1029,7 +1048,7 @@ static int command_pd(int argc, char **argv) task_wake(TASK_ID_PD); } else if (!strncasecmp(argv[1], "state", 5)) { const char * const state_names[] = { - "DISABLED", + "DISABLED", "SUSPENDED", "SNK_DISCONNECTED", "SNK_DISCOVERY", "SNK_REQUESTED", "SNK_TRANSITION", "SNK_READY", "SRC_DISCONNECTED", "SRC_DISCOVERY", "SRC_NEGOCIATE", diff --git a/include/usb_pd.h b/include/usb_pd.h index e8f9168aa7..e02c86f0ca 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -316,6 +316,12 @@ void pd_tx_done(int polarity); */ int pd_rx_started(void); +/** + * Suspend the PD task. + * @param enable pass 0 to resume, anything else to suspend + */ +void pd_set_suspend(int enable); + /* Callback when the hardware has detected an incoming packet */ void pd_rx_event(void); /* Start sampling the CC line for reception */ @@ -329,6 +335,11 @@ void pd_rx_enable_monitoring(void); void pd_rx_disable_monitoring(void); /** + * Deinitialize the hardware used for PD. + */ +void pd_hw_release(void); + +/** * Initialize the hardware used for PD RX/TX. * * @return opaque context for other functions. |