From ba16f505606ca6dad853df6ae177bb0ba10c7015 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Thu, 29 Aug 2024 14:38:41 +0200 Subject: [PATCH] refactor(usb/host): Move P4 HS PHY function to correct LL file Moved usb_wrap_ll_enable_precise_detection() in usb_wrap_ll.h to usb_utmi_ll_enable_precise_detection() in usb_utmi_ll.h Fixes commit 97d30e7c48bfedec59a03ccebb7bc203ba86e126 --- components/hal/esp32p4/include/hal/usb_utmi_ll.h | 15 +++++++++++++-- components/hal/esp32p4/include/hal/usb_wrap_ll.h | 9 --------- components/usb/usb_phy_p4.c | 10 +++++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/components/hal/esp32p4/include/hal/usb_utmi_ll.h b/components/hal/esp32p4/include/hal/usb_utmi_ll.h index e8a21547c0..027bb2e613 100644 --- a/components/hal/esp32p4/include/hal/usb_utmi_ll.h +++ b/components/hal/esp32p4/include/hal/usb_utmi_ll.h @@ -10,6 +10,7 @@ #include "esp_attr.h" #include "soc/lp_clkrst_struct.h" #include "soc/hp_sys_clkrst_struct.h" +#include "soc/hp_system_struct.h" #include "soc/usb_utmi_struct.h" #ifdef __cplusplus @@ -54,7 +55,6 @@ FORCE_INLINE_ATTR void usb_utmi_ll_enable_bus_clock(bool clk_en) */ FORCE_INLINE_ATTR void usb_utmi_ll_reset_register(void) { - //@todo call this function somewhere // Reset the USB_UTMI and USB_DWC_HS LP_AON_CLKRST.hp_usb_clkrst_ctrl1.rst_en_usb_otg20 = 1; LP_AON_CLKRST.hp_usb_clkrst_ctrl1.rst_en_usb_otg20_phy = 1; @@ -62,9 +62,20 @@ FORCE_INLINE_ATTR void usb_utmi_ll_reset_register(void) LP_AON_CLKRST.hp_usb_clkrst_ctrl1.rst_en_usb_otg20 = 0; } -// P_AON_CLKRST.hp_usb_clkrst_ctrlx are shared registers, so this function must be used in an atomic way +// P_AON_CLKRST.hp_usb_clkrst_ctrlx is shared register, so this function must be used in an atomic way #define usb_utmi_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; usb_utmi_ll_reset_register(__VA_ARGS__) +/** + * @brief Enable precise detection of VBUS + * + * @param[in] enable Enable/Disable precise detection + */ +FORCE_INLINE_ATTR void usb_utmi_ll_enable_precise_detection(bool enable) +{ + // Enable VBUS precise detection + HP_SYSTEM.sys_usbotg20_ctrl.sys_otg_suspendm = enable; +} + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32p4/include/hal/usb_wrap_ll.h b/components/hal/esp32p4/include/hal/usb_wrap_ll.h index 113a56fe77..5e6b942366 100644 --- a/components/hal/esp32p4/include/hal/usb_wrap_ll.h +++ b/components/hal/esp32p4/include/hal/usb_wrap_ll.h @@ -12,7 +12,6 @@ #include "soc/lp_system_struct.h" #include "soc/lp_clkrst_struct.h" #include "soc/hp_sys_clkrst_struct.h" -#include "soc/hp_system_struct.h" // For HP_SYSTEM domain #include "soc/usb_wrap_struct.h" #include "hal/usb_wrap_types.h" @@ -263,14 +262,6 @@ FORCE_INLINE_ATTR void usb_wrap_ll_reset_register(void) // P_AON_CLKRST.hp_usb_clkrst_ctrlx are shared registers, so this function must be used in an atomic way #define usb_wrap_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; usb_wrap_ll_reset_register(__VA_ARGS__) -/* ------------------------------- HP System ------------------------------- */ - -FORCE_INLINE_ATTR void usb_wrap_ll_enable_precise_detection(void) -{ - // Enable VBUS precise detection - HP_SYSTEM.sys_usbotg20_ctrl.sys_otg_suspendm = 1; -} - #ifdef __cplusplus } #endif diff --git a/components/usb/usb_phy_p4.c b/components/usb/usb_phy_p4.c index 1d9ef406b5..8365cded17 100644 --- a/components/usb/usb_phy_p4.c +++ b/components/usb/usb_phy_p4.c @@ -7,8 +7,8 @@ // TODO: Refactor during the IDF-9198 #include "sdkconfig.h" #include "soc/usb_dwc_cfg.h" -#include "hal/usb_wrap_hal.h" -#include "hal/usb_utmi_ll.h" +#include "hal/usb_utmi_ll.h" // We don't have usb_utmi_hal yet +#include "esp_private/periph_ctrl.h" // TODO: Remove this file when proper support of P4 PHYs is implemented IDF-7323 #include "esp_private/usb_phy.h" @@ -16,13 +16,17 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r { #if (OTG_HSPHY_INTERFACE != 0) #if CONFIG_IDF_TARGET_ESP32P4 + PERIPH_RCC_ATOMIC() { + usb_utmi_ll_enable_bus_clock(true); + usb_utmi_ll_reset_register(); + } /* Additional setting to solve missing DCONN event on ESP32P4 (IDF-9953). Note: On ESP32P4, the HP_SYSTEM_OTG_SUSPENDM is not connected to 1 by hardware. For correct detection of the device detaching, internal signal should be set to 1 by the software. */ - usb_wrap_ll_enable_precise_detection(); + usb_utmi_ll_enable_precise_detection(true); usb_utmi_ll_configure_ls(&USB_UTMI, true); #endif // CONFIG_IDF_TARGET_ESP32P4 #endif // (OTG_HSPHY_INTERFACE != 0)