Skip to content

Commit ba1ad38

Browse files
kbidanikartben
authored andcommitted
drivers: usb: udc: simplify code of maximum-speed
Add defines to avoid magic values in the dtsi. Replace usb_dc_stm32_get_maximum_speed() with device tree property. - Use DT_INST_STRING_UPPER_TOKEN(0, maximum_speed) to set the USB speed. - Remove PCD_SPEED_FULL initialization. Signed-off-by: Khaoula Bidani <[email protected]>
1 parent 01ddccd commit ba1ad38

File tree

1 file changed

+13
-44
lines changed

1 file changed

+13
-44
lines changed

drivers/usb/udc/udc_stm32.c

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
4040
#define UDC_STM32_IRQ DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, irq)
4141
#define UDC_STM32_IRQ_PRI DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, priority)
4242

43+
/**
44+
* The following defines are used to map the value of the "maxiumum-speed"
45+
* DT property to the corresponding definition used by the STM32 HAL.
46+
*/
47+
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHY)
48+
#define HIGH_SPEED USB_OTG_SPEED_HIGH_IN_FULL
49+
#else
50+
#define HIGH_SPEED USB_OTG_SPEED_HIGH
51+
#endif
52+
53+
#define FULL_SPEED USB_OTG_SPEED_FULL
54+
4355
struct udc_stm32_data {
4456
PCD_HandleTypeDef pcd;
4557
const struct device *dev;
@@ -968,48 +980,6 @@ static const struct udc_stm32_config udc0_cfg = {
968980
.speed_idx = DT_ENUM_IDX_OR(DT_DRV_INST(0), maximum_speed, 1),
969981
};
970982

971-
#if defined(USB_OTG_FS) || defined(USB_OTG_HS)
972-
static uint32_t usb_dc_stm32_get_maximum_speed(void)
973-
{
974-
/*
975-
* STM32L4 series USB LL API doesn't provide HIGH and HIGH_IN_FULL speed
976-
* defines.
977-
*/
978-
#if defined(CONFIG_SOC_SERIES_STM32L4X)
979-
#define USB_OTG_SPEED_HIGH 0U
980-
#define USB_OTG_SPEED_HIGH_IN_FULL 1U
981-
#endif /* CONFIG_SOC_SERIES_STM32L4X */
982-
/*
983-
* If max-speed is not passed via DT, set it to USB controller's
984-
* maximum hardware capability.
985-
*/
986-
#if USB_OTG_HS_EMB_PHY || USB_OTG_HS_ULPI_PHY
987-
uint32_t speed = USB_OTG_SPEED_HIGH;
988-
#else
989-
uint32_t speed = USB_OTG_SPEED_FULL;
990-
#endif
991-
992-
#ifdef USB_MAXIMUM_SPEED
993-
994-
if (!strncmp(USB_MAXIMUM_SPEED, "high-speed", 10)) {
995-
speed = USB_OTG_SPEED_HIGH;
996-
} else if (!strncmp(USB_MAXIMUM_SPEED, "full-speed", 10)) {
997-
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHY)
998-
speed = USB_OTG_SPEED_HIGH_IN_FULL;
999-
#else
1000-
speed = USB_OTG_SPEED_FULL;
1001-
#endif
1002-
} else {
1003-
LOG_DBG("Unsupported maximum speed defined in device tree. "
1004-
"USB controller will default to its maximum HW "
1005-
"capability");
1006-
}
1007-
#endif
1008-
1009-
return speed;
1010-
}
1011-
#endif /* USB_OTG_FS || USB_OTG_HS */
1012-
1013983
static void priv_pcd_prepare(const struct device *dev)
1014984
{
1015985
struct udc_stm32_data *priv = udc_get_private(dev);
@@ -1020,15 +990,14 @@ static void priv_pcd_prepare(const struct device *dev)
1020990
/* Default values */
1021991
priv->pcd.Init.dev_endpoints = cfg->num_endpoints;
1022992
priv->pcd.Init.ep0_mps = cfg->ep0_mps;
1023-
priv->pcd.Init.speed = PCD_SPEED_FULL;
993+
priv->pcd.Init.speed = DT_INST_STRING_UPPER_TOKEN(0, maximum_speed);
1024994

1025995
/* Per controller/Phy values */
1026996
#if defined(USB)
1027997
priv->pcd.Instance = USB;
1028998
#elif defined(USB_DRD_FS)
1029999
priv->pcd.Instance = USB_DRD_FS;
10301000
#elif defined(USB_OTG_FS) || defined(USB_OTG_HS)
1031-
priv->pcd.Init.speed = usb_dc_stm32_get_maximum_speed();
10321001
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
10331002
priv->pcd.Instance = USB_OTG_HS;
10341003
#else

0 commit comments

Comments
 (0)