From 0252365360c86fd7c692db80a024ea586b7aaf46 Mon Sep 17 00:00:00 2001 From: JiangGuangMing Date: Thu, 28 May 2026 11:37:13 +0800 Subject: [PATCH] feat(esp_hal_usb): add usb suspend wakeup status in ll layer Co-authored-by: Cursor --- .../esp32p4/include/hal/usb_utmi_ll.h | 22 ++++++++++++++++--- .../esp32s31/include/hal/usb_utmi_ll.h | 19 ++++++++++++++++ .../esp_hal_usb/include/hal/usb_utmi_hal.h | 12 ++++++++++ components/esp_hal_usb/usb_utmi_hal.c | 10 +++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/components/esp_hal_usb/esp32p4/include/hal/usb_utmi_ll.h b/components/esp_hal_usb/esp32p4/include/hal/usb_utmi_ll.h index 1c2978f95b9..fd34ade1cdb 100644 --- a/components/esp_hal_usb/esp32p4/include/hal/usb_utmi_ll.h +++ b/components/esp_hal_usb/esp32p4/include/hal/usb_utmi_ll.h @@ -11,11 +11,9 @@ #include "soc/lp_clkrst_struct.h" #include "soc/hp_sys_clkrst_struct.h" #include "soc/hp_system_struct.h" +#include "soc/lp_system_struct.h" #include "soc/usb_utmi_struct.h" #include "hal/config.h" -#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300 -#include "soc/lp_system_struct.h" -#endif #ifdef __cplusplus extern "C" { @@ -119,6 +117,24 @@ FORCE_INLINE_ATTR void usb_utmi_ll_enable_precise_detection(bool enable) HP_SYSTEM.sys_usbotg20_ctrl.sys_otg_suspendm = enable; } +/** + * @brief Set USB OTG2.0 suspend state for PMU USB wakeup logic + * + * @param[in] in_suspend True if USB OTG2.0 is suspended + */ +FORCE_INLINE_ATTR void usb_utmi_ll_set_suspend_state(bool in_suspend) +{ + LP_SYS.usb_ctrl.usbotg20_in_suspend = in_suspend; +} + +/** + * @brief Clear USB OTG2.0 wakeup status sent to PMU + */ +FORCE_INLINE_ATTR void usb_utmi_ll_clear_wakeup_status(void) +{ + LP_SYS.usb_ctrl.usbotg20_wakeup_clr = 1; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_usb/esp32s31/include/hal/usb_utmi_ll.h b/components/esp_hal_usb/esp32s31/include/hal/usb_utmi_ll.h index 3ad7538e0f4..e61801c2bf2 100644 --- a/components/esp_hal_usb/esp32s31/include/hal/usb_utmi_ll.h +++ b/components/esp_hal_usb/esp32s31/include/hal/usb_utmi_ll.h @@ -12,6 +12,7 @@ #include "soc/cnnt_sys_struct.h" #include "soc/hp_alive_sys_struct.h" #include "soc/hp_sys_clkrst_struct.h" +#include "soc/lp_system_struct.h" #include "soc/reg_base.h" #include "soc/usb_utmi_struct.h" @@ -146,6 +147,24 @@ FORCE_INLINE_ATTR void usb_utmi_ll_enable_precise_detection(bool enable) HP_ALIVE_SYS.usb_otghs_ctrl.reg_usb_otghs_phy_otg_suspendm = enable; } +/** + * @brief Set USB OTG2.0 suspend state for PMU USB wakeup logic + * + * @param[in] in_suspend True if USB OTG2.0 is suspended + */ +FORCE_INLINE_ATTR void usb_utmi_ll_set_suspend_state(bool in_suspend) +{ + LP_SYS.usb_ctrl.usbotghs_in_suspend = in_suspend; +} + +/** + * @brief Clear USB OTG2.0 wakeup status sent to PMU + */ +FORCE_INLINE_ATTR void usb_utmi_ll_clear_wakeup_status(void) +{ + LP_SYS.usb_ctrl.usbotghs_wakeup_clr = 1; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_usb/include/hal/usb_utmi_hal.h b/components/esp_hal_usb/include/hal/usb_utmi_hal.h index ad7ba50f6c2..1466c57b516 100644 --- a/components/esp_hal_usb/include/hal/usb_utmi_hal.h +++ b/components/esp_hal_usb/include/hal/usb_utmi_hal.h @@ -67,6 +67,18 @@ void _usb_utmi_hal_disable(void); */ void usb_utmi_hal_enable_data_pulldowns(bool enable); +/** + * @brief Set USB OTG2.0 suspend state for PMU USB wakeup logic + * + * @param[in] in_suspend True if USB OTG2.0 is suspended + */ +void usb_utmi_hal_set_suspend_state(bool in_suspend); + +/** + * @brief Clear USB OTG2.0 wakeup status sent to PMU + */ +void usb_utmi_hal_clear_wakeup_status(void); + #endif // (SOC_USB_UTMI_PHY_NUM > 0) #ifdef __cplusplus diff --git a/components/esp_hal_usb/usb_utmi_hal.c b/components/esp_hal_usb/usb_utmi_hal.c index 137f493d99d..76ba413852c 100644 --- a/components/esp_hal_usb/usb_utmi_hal.c +++ b/components/esp_hal_usb/usb_utmi_hal.c @@ -28,6 +28,16 @@ void usb_utmi_hal_enable_data_pulldowns(bool enable) usb_utmi_ll_enable_data_pulldowns(enable); } +void usb_utmi_hal_set_suspend_state(bool in_suspend) +{ + usb_utmi_ll_set_suspend_state(in_suspend); +} + +void usb_utmi_hal_clear_wakeup_status(void) +{ + usb_utmi_ll_clear_wakeup_status(); +} + void _usb_utmi_hal_disable(void) { _usb_utmi_ll_enable_bus_clock(false);