summaryrefslogtreecommitdiff
path: root/chip/stm32/usb.c
diff options
context:
space:
mode:
authorJes B. Klinke <jbk@chromium.org>2021-08-30 14:52:26 -0700
committerCommit Bot <commit-bot@chromium.org>2021-09-08 18:57:36 +0000
commitf2af0a3a74192876fc1b72706813d756393da167 (patch)
treea53007357e2be115dab1aace09365a4845e109af /chip/stm32/usb.c
parentf351c02b70c6a7d2137d3770e11e7c3a3850a1c8 (diff)
downloadchrome-ec-f2af0a3a74192876fc1b72706813d756393da167.tar.gz
chip/stm32: Factor family specific clock logic out of usb.c
The register for enabling USB register clock appears to have been identical across F0, F3, and G4 families, but for L5 it is different. Rather than having #ifdef in usb.c (as I recently committed), this CL will move the clock logic into clock_enable_module() where it arguably belonged all the time. Additionally: Some of the chip families make use of a clock_mask in their implementation of clock_enable_module(), but since the module_id enum has more than 32 value, until now, some values (among those MODULE_USB) would result in overflow, causing new_mask to be identical to clock_mask, and the USB case could have never been reached. BUG=b:192262089 TEST=Compile servo_v4 without linker errors BRANCH=none Signed-off-by: Jes Bodi Klinke <jbk@chromium.org> Change-Id: I7c29339f45eb513e3e78f662797a70543912c8c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3130733 Reviewed-by: Scott Collyer <scollyer@chromium.org>
Diffstat (limited to 'chip/stm32/usb.c')
-rw-r--r--chip/stm32/usb.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c
index 70acdf6486..0077815a27 100644
--- a/chip/stm32/usb.c
+++ b/chip/stm32/usb.c
@@ -677,14 +677,7 @@ DECLARE_IRQ(STM32_IRQ_USB_LP, usb_interrupt, 1);
void usb_init(void)
{
- /* Enable USB device clock. */
-#if defined(STM32_RCC_APB1ENR2_USBFSEN)
- STM32_RCC_APB1ENR2 |= STM32_RCC_APB1ENR2_USBFSEN;
-#else
- STM32_RCC_APB1ENR |= STM32_RCC_PB1_USB;
-#endif
-
- /* we need a proper 48MHz clock */
+ /* Enable USB device clock, possibly increasing system clock to 48MHz */
clock_enable_module(MODULE_USB, 1);
/* configure the pinmux */
@@ -747,26 +740,15 @@ void usb_release(void)
/* unset pinmux */
gpio_config_module(MODULE_USB, 0);
- /* disable 48MHz clock */
+ /* disable USB device clock, possibly slowing down system clock */
clock_enable_module(MODULE_USB, 0);
-
- /* disable USB device clock */
-#if defined(STM32_RCC_APB1ENR2_USBFSEN)
- STM32_RCC_APB1ENR2 &= ~STM32_RCC_APB1ENR2_USBFSEN;
-#else
- STM32_RCC_APB1ENR &= ~STM32_RCC_PB1_USB;
-#endif
}
/* ensure the host disconnects and reconnects over a sysjump */
DECLARE_HOOK(HOOK_SYSJUMP, usb_release, HOOK_PRIO_DEFAULT);
int usb_is_enabled(void)
{
-#if defined(STM32_RCC_APB1ENR2_USBFSEN)
- return (STM32_RCC_APB1ENR2 & STM32_RCC_APB1ENR2_USBFSEN) ? 1 : 0;
-#else
- return (STM32_RCC_APB1ENR & STM32_RCC_PB1_USB) ? 1 : 0;
-#endif
+ return clock_is_module_enabled(MODULE_USB);
}
void *memcpy_to_usbram(void *dest, const void *src, size_t n)