summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Berger <[email protected]>2026-02-19 23:03:32 +0100
committerCédric Berger <[email protected]>2026-02-19 23:03:32 +0100
commitc8265a3709ebe6b5f77aa3b5bb148740c5818f00 (patch)
tree65edc5234bc870819159f1058f9da9b22b814676
parentdb1ff5d1692a4407496284b6684438256e1988db (diff)
Introduce TUH_CFGID_PHY_SPEED configure option
-rw-r--r--src/host/usbh.h1
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.c9
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.h3
-rw-r--r--src/portable/synopsys/dwc2/hcd_dwc2.c18
4 files changed, 22 insertions, 9 deletions
diff --git a/src/host/usbh.h b/src/host/usbh.h
index d86efbcb2..03577ba3f 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -93,6 +93,7 @@ typedef struct {
// ConfigID for tuh_configure()
enum {
TUH_CFGID_INVALID = 0,
+ TUH_CFGID_PHY_SPEED = 10, // cfg_param: tusb_speed_t
TUH_CFGID_RPI_PIO_USB_CONFIGURATION = 100, // cfg_param: pio_usb_configuration_t
TUH_CFGID_MAX3421 = 200,
TUH_CFGID_FSDEV = 300,
diff --git a/src/portable/synopsys/dwc2/dwc2_common.c b/src/portable/synopsys/dwc2/dwc2_common.c
index 5429af440..429c56123 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.c
+++ b/src/portable/synopsys/dwc2/dwc2_common.c
@@ -187,8 +187,13 @@ bool dwc2_core_is_highspeed_phy(dwc2_regs_t* dwc2, tusb_role_t role) {
}
#endif
#if CFG_TUH_ENABLED
- if (role == TUSB_ROLE_HOST && !TUH_OPT_HIGH_SPEED) {
- return false;
+ if (role == TUSB_ROLE_HOST) {
+ if (_hcd_cfg_phy_speed == TUSB_SPEED_HIGH)
+ return true;
+ if (_hcd_cfg_phy_speed < TUSB_SPEED_HIGH)
+ return false;
+ if (!TUH_OPT_HIGH_SPEED)
+ return false;
}
#endif
diff --git a/src/portable/synopsys/dwc2/dwc2_common.h b/src/portable/synopsys/dwc2/dwc2_common.h
index b03fecad9..16a18c673 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.h
+++ b/src/portable/synopsys/dwc2/dwc2_common.h
@@ -76,6 +76,9 @@ enum {
//--------------------------------------------------------------------+
// Core/Controller
//--------------------------------------------------------------------+
+
+extern tusb_speed_t _hcd_cfg_phy_speed;
+
TU_ATTR_ALWAYS_INLINE static inline dwc2_regs_t* DWC2_REG(uint8_t rhport) {
if (rhport >= DWC2_CONTROLLER_COUNT) {
// user mis-configured, ignore and use first controller
diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c
index 2d667eb43..99be779ef 100644
--- a/src/portable/synopsys/dwc2/hcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/hcd_dwc2.c
@@ -112,6 +112,7 @@ typedef struct {
} hcd_data_t;
hcd_data_t _hcd_data;
+tusb_speed_t _hcd_cfg_phy_speed = TUSB_SPEED_AUTO;
//--------------------------------------------------------------------
//
@@ -392,15 +393,13 @@ static void dfifo_host_init(uint8_t rhport) {
// optional hcd configuration, called by tuh_configure()
bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) {
(void) rhport;
- (void) cfg_id;
- (void) cfg_param;
-
+ TU_VERIFY(cfg_id == TUH_CFGID_PHY_SPEED && cfg_param != NULL);
+ _hcd_cfg_phy_speed = *(const tusb_speed_t *)cfg_param;
return true;
}
// Initialize controller to host mode
bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
- (void) rh_init;
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
tu_memclr(&_hcd_data, sizeof(_hcd_data));
@@ -412,9 +411,6 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
//------------- 3.1 Host Initialization -------------//
- // work at max supported speed
- dwc2->hcfg &= ~HCFG_FSLS_ONLY;
-
// Enable HFIR reload
if (dwc2->gsnpsid >= DWC2_CORE_REV_2_92a) {
dwc2->hfir |= HFIR_RELOAD_CTRL;
@@ -432,6 +428,14 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
dwc2_stm32_gccfg_cfg(dwc2, false, true);
#endif
+ if (highspeed_phy && rh_init->speed < TUSB_SPEED_HIGH) {
+ // disable high speed mode
+ dwc2->hcfg |= HCFG_FSLS_ONLY;
+ } else {
+ // work at max supported speed
+ dwc2->hcfg &= ~HCFG_FSLS_ONLY;
+ }
+
// configure fixed-allocated fifo scheme
dfifo_host_init(rhport);