Skip to content

Commit 01ddccd

Browse files
kbidanikartben
authored andcommitted
drivers: usb: device: 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 e359cc6 commit 01ddccd

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed

drivers/usb/device/usb_dc_stm32.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ LOG_MODULE_REGISTER(usb_dc_stm32);
6767

6868
static const struct stm32_pclken pclken[] = STM32_DT_INST_CLOCKS(0);
6969

70-
#if DT_INST_NODE_HAS_PROP(0, maximum_speed)
71-
#define USB_MAXIMUM_SPEED DT_INST_PROP(0, maximum_speed)
72-
#endif
73-
7470
PINCTRL_DT_INST_DEFINE(0);
7571
static const struct pinctrl_dev_config *usb_pcfg =
7672
PINCTRL_DT_INST_DEV_CONFIG_GET(0);
@@ -89,6 +85,18 @@ static const struct gpio_dt_spec ulpi_reset =
8985
GPIO_DT_SPEC_GET_OR(DT_PHANDLE(DT_INST(0, st_stm32_otghs), phys), reset_gpios, {0});
9086
#endif
9187

88+
/**
89+
* The following defines are used to map the value of the "maxiumum-speed"
90+
* DT property to the corresponding definition used by the STM32 HAL.
91+
*/
92+
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHYC) || \
93+
defined(USB_OTG_HS_EMB_PHY)
94+
#define HIGH_SPEED USB_OTG_SPEED_HIGH_IN_FULL
95+
#else
96+
#define HIGH_SPEED USB_OTG_SPEED_HIGH
97+
#endif
98+
99+
#define FULL_SPEED USB_OTG_SPEED_FULL
92100
/*
93101
* USB, USB_OTG_FS and USB_DRD_FS are defined in STM32Cube HAL and allows to
94102
* distinguish between two kind of USB DC. STM32 F0, F3, L0 and G4 series
@@ -432,54 +440,19 @@ static int usb_dc_stm32_clock_disable(void)
432440
return 0;
433441
}
434442

435-
#if defined(USB_OTG_FS) || defined(USB_OTG_HS)
436-
static uint32_t usb_dc_stm32_get_maximum_speed(void)
437-
{
438-
/*
439-
* If max-speed is not passed via DT, set it to USB controller's
440-
* maximum hardware capability.
441-
*/
442-
#if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY || USB_OTG_HS_ULPI_PHY
443-
uint32_t speed = USB_OTG_SPEED_HIGH;
444-
#else
445-
uint32_t speed = USB_OTG_SPEED_FULL;
446-
#endif
447-
448-
#ifdef USB_MAXIMUM_SPEED
449-
450-
if (!strncmp(USB_MAXIMUM_SPEED, "high-speed", 10)) {
451-
speed = USB_OTG_SPEED_HIGH;
452-
} else if (!strncmp(USB_MAXIMUM_SPEED, "full-speed", 10)) {
453-
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHYC) || \
454-
defined(USB_OTG_HS_EMB_PHY)
455-
speed = USB_OTG_SPEED_HIGH_IN_FULL;
456-
#else
457-
speed = USB_OTG_SPEED_FULL;
458-
#endif
459-
} else {
460-
LOG_DBG("Unsupported maximum speed defined in device tree. "
461-
"USB controller will default to its maximum HW "
462-
"capability");
463-
}
464-
#endif
465-
466-
return speed;
467-
}
468-
#endif /* USB_OTG_FS || USB_OTG_HS */
469-
470443
static int usb_dc_stm32_init(void)
471444
{
472445
HAL_StatusTypeDef status;
473446
int ret;
474447
unsigned int i;
475448

449+
usb_dc_stm32_state.pcd.Init.speed = DT_INST_STRING_UPPER_TOKEN(0, maximum_speed);
476450
#if defined(USB) || defined(USB_DRD_FS)
477451
#ifdef USB
478452
usb_dc_stm32_state.pcd.Instance = USB;
479453
#else
480454
usb_dc_stm32_state.pcd.Instance = USB_DRD_FS;
481455
#endif
482-
usb_dc_stm32_state.pcd.Init.speed = PCD_SPEED_FULL;
483456
usb_dc_stm32_state.pcd.Init.dev_endpoints = USB_NUM_BIDIR_ENDPOINTS;
484457
usb_dc_stm32_state.pcd.Init.phy_itface = PCD_PHY_EMBEDDED;
485458
usb_dc_stm32_state.pcd.Init.ep0_mps = PCD_EP0MPS_64;
@@ -491,7 +464,6 @@ static int usb_dc_stm32_init(void)
491464
usb_dc_stm32_state.pcd.Instance = USB_OTG_FS;
492465
#endif
493466
usb_dc_stm32_state.pcd.Init.dev_endpoints = USB_NUM_BIDIR_ENDPOINTS;
494-
usb_dc_stm32_state.pcd.Init.speed = usb_dc_stm32_get_maximum_speed();
495467
#if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
496468
usb_dc_stm32_state.pcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
497469
#elif USB_OTG_HS_ULPI_PHY

0 commit comments

Comments
 (0)