Skip to content

Commit 7f06d0a

Browse files
committed
drivers: usb: device_stm32: imporve usb code maintainability
Replace the direct call to LL_AHBx_GRP1_EnableClock with the clock control API. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
1 parent c77edf0 commit 7f06d0a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/usb/device/usb_dc_stm32.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ static const struct gpio_dt_spec ulpi_reset =
101101
#else
102102
#define USB_DC_STM32_FULL_SPEED USB_OTG_SPEED_FULL
103103
#endif
104+
105+
#if DT_NODE_HAS_PROP(DT_PHANDLE(DT_INST(0, DT_DRV_COMPAT), phys), clocks)
106+
#define HAS_PHY_CLK 1
107+
static const struct stm32_pclken phy_pclken[] = STM32_DT_CLOCKS(DT_INST_PHANDLE(0, phys));
108+
#endif
109+
104110
/*
105111
* USB, USB_OTG_FS and USB_DRD_FS are defined in STM32Cube HAL and allows to
106112
* distinguish between two kind of USB DC. STM32 F0, F3, L0 and G4 series
@@ -225,8 +231,6 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
225231

226232
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy)
227233

228-
static const struct stm32_pclken phy_pclken[] = STM32_DT_CLOCKS(DT_INST_PHANDLE(0, phys));
229-
230234
static int usb_dc_stm32u5_phy_clock_select(const struct device *const clk)
231235
{
232236
static const struct {
@@ -400,31 +404,27 @@ static int usb_dc_stm32_clock_enable(void)
400404

401405
#endif /* RCC_CFGR_OTGFSPRE / RCC_CFGR_USBPRE */
402406

403-
#if USB_OTG_HS_ULPI_PHY
404-
#if defined(CONFIG_SOC_SERIES_STM32H7X)
405-
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_USB1OTGHSULPI);
406-
#else
407-
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
407+
#ifdef HAS_PHY_CLK
408+
if (clock_control_on(clk, (clock_control_subsys_t *)&phy_pclken[0]) != 0) {
409+
LOG_ERR("Unable to enable USB_PHY clock");
410+
return -EIO;
411+
}
408412
#endif
409-
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) /* USB_OTG_HS_ULPI_PHY */
413+
414+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
410415
/* Disable ULPI interface (for external high-speed PHY) clock in sleep/low-power mode.
411416
* It is disabled by default in run power mode, no need to disable it.
412417
*/
413418
#if defined(CONFIG_SOC_SERIES_STM32H7X)
414419
LL_AHB1_GRP1_DisableClockSleep(LL_AHB1_GRP1_PERIPH_USB1OTGHSULPI);
415420
#elif defined(CONFIG_SOC_SERIES_STM32U5X)
416-
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_USBPHY);
417421
/* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */
418422
LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS ||
419423
LL_AHB2_GRP1_PERIPH_USBPHY);
420424
#else
421425
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
422426
#endif
423-
424-
#if USB_OTG_HS_EMB_PHYC
425-
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_OTGPHYC);
426427
#endif
427-
#endif /* USB_OTG_HS_ULPI_PHY */
428428

429429
return 0;
430430
}

0 commit comments

Comments
 (0)