Skip to content

Commit a4b2352

Browse files
committed
drivers: udc_stm32: rework speed selection logic
basically only consider UDC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED and the underlaying phy. additionally, full-speed can be forced via maximum_speed DT property Signed-off-by: Martin Gysel <[email protected]>
1 parent 2b2889e commit a4b2352

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

drivers/usb/udc/udc_stm32.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,30 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
4141
#define UDC_STM32_IRQ DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, irq)
4242
#define UDC_STM32_IRQ_PRI DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, priority)
4343

44-
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
44+
#define USB_OTG_HS_EMB_PHYC (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
45+
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
46+
47+
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) && \
4548
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
4649

4750
#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
4851
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
4952

5053
/**
51-
* The following defines are used to map the value of the "maxiumum-speed"
52-
* DT property to the corresponding definition used by the STM32 HAL.
54+
* Select the desired speed based on enabled high speed support and phy.
5355
*/
54-
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHY)
55-
#define UDC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH_IN_FULL
56-
#else
57-
#define UDC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH
58-
#endif
59-
60-
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usb)
61-
#define UDC_STM32_FULL_SPEED PCD_SPEED_FULL
56+
#if CONFIG_UDC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED && \
57+
DT_ENUM_IDX_OR(id, maximum_speed, UDC_BUS_SPEED_HS) != UDC_BUS_SPEED_HS && \
58+
!(USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY || USB_OTG_HS_ULPI_PHY)
59+
#error "High speed support enabled by USB device controller (Kconfig) but not supported by the phy (devicetree)"
60+
#elif CONFIG_UDC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED
61+
#define UDC_STM32_SPEED USB_OTG_SPEED_HIGH
62+
#elif defined(CONFIG_SOC_SERIES_STM32H7X) || USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
63+
#define UDC_STM32_SPEED USB_OTG_SPEED_HIGH_IN_FULL
64+
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usb)
65+
#define UDC_STM32_SPEED PCD_SPEED_FULL
6266
#else
63-
#define UDC_STM32_FULL_SPEED USB_OTG_SPEED_FULL
67+
#define UDC_STM32_SPEED USB_OTG_SPEED_FULL
6468
#endif
6569

6670
struct udc_stm32_data {
@@ -81,7 +85,6 @@ struct udc_stm32_config {
8185
uint32_t dram_size;
8286
uint16_t ep0_mps;
8387
uint16_t ep_mps;
84-
int speed_idx;
8588
};
8689

8790
enum udc_stm32_msg_type {
@@ -982,7 +985,6 @@ static const struct udc_stm32_config udc0_cfg = {
982985
.pma_offset = USB_BTABLE_SIZE,
983986
.ep0_mps = EP0_MPS,
984987
.ep_mps = EP_MPS,
985-
.speed_idx = DT_ENUM_IDX_OR(DT_DRV_INST(0), maximum_speed, 1),
986988
};
987989

988990
static void priv_pcd_prepare(const struct device *dev)
@@ -995,7 +997,7 @@ static void priv_pcd_prepare(const struct device *dev)
995997
/* Default values */
996998
priv->pcd.Init.dev_endpoints = cfg->num_endpoints;
997999
priv->pcd.Init.ep0_mps = cfg->ep0_mps;
998-
priv->pcd.Init.speed = UTIL_CAT(UDC_STM32_, DT_INST_STRING_UPPER_TOKEN(0, maximum_speed));
1000+
priv->pcd.Init.speed = UDC_STM32_SPEED;
9991001

10001002
/* Per controller/Phy values */
10011003
#if defined(USB)
@@ -1006,13 +1008,13 @@ static void priv_pcd_prepare(const struct device *dev)
10061008
priv->pcd.Instance = (USB_OTG_GlobalTypeDef *)UDC_STM32_BASE_ADDRESS;
10071009
#endif /* USB */
10081010

1009-
#if USB_OTG_HS_EMB_PHY
1011+
#if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
10101012
priv->pcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
10111013
#elif USB_OTG_HS_ULPI_PHY
10121014
priv->pcd.Init.phy_itface = USB_OTG_ULPI_PHY;
10131015
#else
10141016
priv->pcd.Init.phy_itface = PCD_PHY_EMBEDDED;
1015-
#endif /* USB_OTG_HS_EMB_PHY */
1017+
#endif /* USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY */
10161018
}
10171019

10181020
static const struct stm32_pclken pclken[] = STM32_DT_INST_CLOCKS(0);
@@ -1146,7 +1148,7 @@ static int priv_clock_enable(void)
11461148
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
11471149
#endif /* defined(CONFIG_SOC_SERIES_STM32H7X) */
11481150

1149-
#if USB_OTG_HS_EMB_PHY
1151+
#if USB_OTG_HS_EMB_PHYC
11501152
#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
11511153
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_OTGPHYC);
11521154
#endif
@@ -1244,9 +1246,9 @@ static int udc_stm32_driver_init0(const struct device *dev)
12441246
data->caps.rwup = true;
12451247
data->caps.out_ack = false;
12461248
data->caps.mps0 = UDC_MPS0_64;
1247-
if (cfg->speed_idx == 2) {
1248-
data->caps.hs = true;
1249-
}
1249+
#if UDC_STM32_SPEED == USB_OTG_SPEED_HIGH
1250+
data->caps.hs = true;
1251+
#endif
12501252

12511253
priv->dev = dev;
12521254
priv->irq = UDC_STM32_IRQ;

0 commit comments

Comments
 (0)