From e2b27d820db130c2d19c9756e01839db2a451cf1 Mon Sep 17 00:00:00 2001 From: Pushpal Sidhu Date: Wed, 25 Apr 2018 13:44:23 -0700 Subject: [PATCH] drivers: usb_dc_stm32: enable VDDUSB if needed This is required on boards that isolate VDDUSB from the system. Signed-off-by: Pushpal Sidhu --- arch/arm/soc/st_stm32/stm32l4/soc.h | 5 +++++ drivers/usb/device/usb_dc_stm32.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/arm/soc/st_stm32/stm32l4/soc.h b/arch/arm/soc/st_stm32/stm32l4/soc.h index eaeb4103c8a..2397331bb32 100644 --- a/arch/arm/soc/st_stm32/stm32l4/soc.h +++ b/arch/arm/soc/st_stm32/stm32l4/soc.h @@ -55,6 +55,11 @@ #include #endif +#ifdef CONFIG_USB +/* Required to remove USB transceiver supply isolation */ +#include +#endif /* CONFIG_USB */ + #endif /* !_ASMLANGUAGE */ #endif /* _STM32L4X_SOC_H_ */ diff --git a/drivers/usb/device/usb_dc_stm32.c b/drivers/usb/device/usb_dc_stm32.c index c545997ea2b..0c23569fca5 100644 --- a/drivers/usb/device/usb_dc_stm32.c +++ b/drivers/usb/device/usb_dc_stm32.c @@ -330,6 +330,21 @@ int usb_dc_attach(void) return ret; } + /* + * Required for at least STM32L4 devices as they electrically + * isolate USB features from VDDUSB. It must be enabled before + * USB can function. Refer to DM00310109, section 5.1.3. + */ +#ifdef PWR_CR2_PVME1 + if (LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_PWR)) { + LL_PWR_EnableVddUSB(); + } else { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); + LL_PWR_EnableVddUSB(); + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_PWR); + } +#endif /* PWR_CR2_PVME1 */ + return 0; }