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 */ @@ -328,6 +334,11 @@ void pd_rx_enable_monitoring(void); /* stop listening to the CC wire during transmissions */ 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. *