summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-03-05 10:01:40 +0700
committerhathach <[email protected]>2026-03-05 10:01:40 +0700
commit1efe4cd0e84e965db7c5056f4339c83102e997ab (patch)
tree8961e6ced4020de3cc5f0b7e632e27d2c923a01f
parent3fb668c2ac7ed612102221d086179d4a61f03c8d (diff)
add hs_phy_type parameter to dwc2_phy_deinit for selective PHY deinitialization across all MCUs
-rw-r--r--src/portable/synopsys/dwc2/dwc2_at32.h3
-rw-r--r--src/portable/synopsys/dwc2/dwc2_bcm.h3
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.c4
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.h2
-rw-r--r--src/portable/synopsys/dwc2/dwc2_efm32.h4
-rw-r--r--src/portable/synopsys/dwc2/dwc2_esp32.h3
-rw-r--r--src/portable/synopsys/dwc2/dwc2_gd32.h3
-rw-r--r--src/portable/synopsys/dwc2/dwc2_nrf.h3
-rw-r--r--src/portable/synopsys/dwc2/dwc2_stm32.h24
-rw-r--r--src/portable/synopsys/dwc2/dwc2_xmc.h4
10 files changed, 31 insertions, 22 deletions
diff --git a/src/portable/synopsys/dwc2/dwc2_at32.h b/src/portable/synopsys/dwc2/dwc2_at32.h
index 95ee8a8e1..fa6d10c12 100644
--- a/src/portable/synopsys/dwc2/dwc2_at32.h
+++ b/src/portable/synopsys/dwc2/dwc2_at32.h
@@ -113,7 +113,8 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t *dwc2, uint8_
}
// MCU specific PHY deinit, disable PHY power
-TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_deinit(dwc2_regs_t *dwc2) {
+TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_deinit(dwc2_regs_t *dwc2, uint8_t hs_phy_type) {
+ (void) hs_phy_type;
dwc2->stm32_gccfg &= ~(STM32_GCCFG_PWRDWN | STM32_GCCFG_DCDEN | STM32_GCCFG_PDEN);
}
diff --git a/src/portable/synopsys/dwc2/dwc2_bcm.h b/src/portable/synopsys/dwc2/dwc2_bcm.h
index 852db15e5..00842bba2 100644
--- a/src/portable/synopsys/dwc2/dwc2_bcm.h
+++ b/src/portable/synopsys/dwc2/dwc2_bcm.h
@@ -74,8 +74,9 @@ static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
}
// MCU specific PHY deinit, disable PHY power
-static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2) {
+static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2, uint8_t hs_phy_type) {
(void) dwc2;
+ (void) hs_phy_type;
// nothing to do
}
diff --git a/src/portable/synopsys/dwc2/dwc2_common.c b/src/portable/synopsys/dwc2/dwc2_common.c
index 4e8e1ff04..33eabaeab 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.c
+++ b/src/portable/synopsys/dwc2/dwc2_common.c
@@ -256,7 +256,9 @@ void dwc2_core_deinit(uint8_t rhport) {
dwc2->pcgcctl |= PCGCCTL_STOPPCLK | PCGCCTL_GATEHCLK;
// MCU-specific PHY deinit (disable PHY power)
- dwc2_phy_deinit(dwc2);
+ const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2};
+ const uint8_t hs_phy_type = (dwc2->gusbcfg & GUSBCFG_PHYSEL) ? GHWCFG2_HSPHY_NOT_SUPPORTED : ghwcfg2.hs_phy_type;
+ dwc2_phy_deinit(dwc2, hs_phy_type);
}
// void dwc2_core_handle_common_irq(uint8_t rhport, bool in_isr) {
diff --git a/src/portable/synopsys/dwc2/dwc2_common.h b/src/portable/synopsys/dwc2/dwc2_common.h
index ac97ab3d5..9f28ab2e0 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.h
+++ b/src/portable/synopsys/dwc2/dwc2_common.h
@@ -42,7 +42,7 @@
// - _dwc2_controller[]: array of controllers
// - DWC2_EP_MAX: largest EP counts of all controllers
// - dwc2_phy_init/dwc2_phy_update: phy init called before and after core reset
-// - dwc2_phy_deinit: phy deinit to disable PHY power
+// - dwc2_phy_deinit(dwc2, hs_phy_type): phy deinit to disable PHY power, only deinit the phy used by core
// - dwc2_dcd_int_enable/dwc2_dcd_int_disable
// - dwc2_remote_wakeup_delay
diff --git a/src/portable/synopsys/dwc2/dwc2_efm32.h b/src/portable/synopsys/dwc2/dwc2_efm32.h
index f808b567c..e1cb7c769 100644
--- a/src/portable/synopsys/dwc2/dwc2_efm32.h
+++ b/src/portable/synopsys/dwc2/dwc2_efm32.h
@@ -73,9 +73,9 @@ static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
}
// MCU specific PHY deinit, disable PHY power
-static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2) {
+static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2, uint8_t hs_phy_type) {
(void) dwc2;
-
+ (void) hs_phy_type;
// Disable PHY pin
USB->ROUTE = 0;
}
diff --git a/src/portable/synopsys/dwc2/dwc2_esp32.h b/src/portable/synopsys/dwc2/dwc2_esp32.h
index f4fa0bf8b..ff9f216bd 100644
--- a/src/portable/synopsys/dwc2/dwc2_esp32.h
+++ b/src/portable/synopsys/dwc2/dwc2_esp32.h
@@ -122,8 +122,9 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_
}
// MCU specific PHY deinit, disable PHY power
-TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_deinit(dwc2_regs_t* dwc2) {
+TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_deinit(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
(void)dwc2;
+ (void)hs_phy_type;
// PHY managed by ESP-IDF
}
diff --git a/src/portable/synopsys/dwc2/dwc2_gd32.h b/src/portable/synopsys/dwc2/dwc2_gd32.h
index 26b924161..ccbf93a76 100644
--- a/src/portable/synopsys/dwc2/dwc2_gd32.h
+++ b/src/portable/synopsys/dwc2/dwc2_gd32.h
@@ -86,8 +86,9 @@ static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
}
// MCU specific PHY deinit, disable PHY power
-static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2) {
+static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2, uint8_t hs_phy_type) {
(void) dwc2;
+ (void) hs_phy_type;
// nothing to do
}
diff --git a/src/portable/synopsys/dwc2/dwc2_nrf.h b/src/portable/synopsys/dwc2/dwc2_nrf.h
index 17d21518b..51f2d684f 100644
--- a/src/portable/synopsys/dwc2/dwc2_nrf.h
+++ b/src/portable/synopsys/dwc2/dwc2_nrf.h
@@ -53,8 +53,9 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_
}
// MCU specific PHY deinit, disable PHY power
-TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_deinit(dwc2_regs_t* dwc2) {
+TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_deinit(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
(void)dwc2;
+ (void)hs_phy_type;
}
// MCU specific PHY update, it is called AFTER init() and core reset
diff --git a/src/portable/synopsys/dwc2/dwc2_stm32.h b/src/portable/synopsys/dwc2/dwc2_stm32.h
index cc972e957..259ad21b9 100644
--- a/src/portable/synopsys/dwc2/dwc2_stm32.h
+++ b/src/portable/synopsys/dwc2/dwc2_stm32.h
@@ -265,17 +265,19 @@ static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
}
// MCU specific PHY deinit, disable PHY power
-static inline void dwc2_phy_deinit(dwc2_regs_t* dwc2) {
- // Disable on-chip FS PHY
- dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN;
-
- // Disable HS PHY if present
- #ifdef USB_HS_PHYC
- dwc2->stm32_gccfg &= ~STM32_GCCFG_PHYHSEN;
- // Disable PLL and LDO
- USB_HS_PHYC->USB_HS_PHYC_PLL &= ~USB_HS_PHYC_PLL_PLLEN;
- USB_HS_PHYC->USB_HS_PHYC_LDO &= ~USB_HS_PHYC_LDO_ENABLE;
- #endif
+static inline void dwc2_phy_deinit(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
+ if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) {
+ // Disable on-chip FS PHY
+ dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN;
+ } else {
+ // Disable HS PHY
+ #ifdef USB_HS_PHYC
+ dwc2->stm32_gccfg &= ~STM32_GCCFG_PHYHSEN;
+ // Disable PLL and LDO
+ USB_HS_PHYC->USB_HS_PHYC_PLL &= ~USB_HS_PHYC_PLL_PLLEN;
+ USB_HS_PHYC->USB_HS_PHYC_LDO &= ~USB_HS_PHYC_LDO_ENABLE;
+ #endif
+ }
}
// MCU specific PHY update, it is called AFTER init() and core reset
diff --git a/src/portable/synopsys/dwc2/dwc2_xmc.h b/src/portable/synopsys/dwc2/dwc2_xmc.h
index e38935e9c..aca3873df 100644
--- a/src/portable/synopsys/dwc2/dwc2_xmc.h
+++ b/src/portable/synopsys/dwc2/dwc2_xmc.h
@@ -72,9 +72,9 @@ static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
}
// MCU specific PHY deinit, disable PHY power
-static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2) {
+static inline void dwc2_phy_deinit(dwc2_regs_t * dwc2, uint8_t hs_phy_type) {
(void) dwc2;
-
+ (void) hs_phy_type;
// nothing to do
}