summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Chen <ddchen@chromium.org>2014-08-14 17:46:21 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-16 05:22:50 +0000
commitf3c308108b88ff4c8ac276269da056560265bf1b (patch)
tree849452fd3e4188636965091bcce94ab68d521304
parent29b18b820ae8f1b26a4698366a0a66747115b743 (diff)
downloadchrome-ec-f3c308108b88ff4c8ac276269da056560265bf1b.tar.gz
usb: add CONFIG_USB_INHIBIT to prevent automatically starting USB
BUG=none BRANCH=none TEST=usb does not autostart, and can be enabled/disabled Change-Id: I22a7bf3ca9cb7013cc4964dbdabff7524985d9ba Signed-off-by: Dominic Chen <ddchen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/212509 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--chip/stm32/usb.c28
-rw-r--r--include/config.h3
-rw-r--r--include/usb.h4
3 files changed, 34 insertions, 1 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c
index 63a406e48d..ea26eeb93d 100644
--- a/chip/stm32/usb.c
+++ b/chip/stm32/usb.c
@@ -221,7 +221,7 @@ void usb_interrupt(void)
}
DECLARE_IRQ(STM32_IRQ_USB_LP, usb_interrupt, 1);
-static void usb_init(void)
+void usb_init(void)
{
/* Enable USB device clock. */
STM32_RCC_APB1ENR |= STM32_RCC_PB1_USB;
@@ -262,4 +262,30 @@ static void usb_init(void)
CPRINTF("USB init done\n");
}
+#ifndef CONFIG_USB_INHIBIT
DECLARE_HOOK(HOOK_INIT, usb_init, HOOK_PRIO_DEFAULT);
+#endif
+
+void usb_release(void)
+{
+ /* signal disconnect to host */
+#ifdef CHIP_VARIANT_STM32L15X
+ STM32_SYSCFG_PMC &= ~1;
+#elif defined(CHIP_FAMILY_STM32F0)
+ STM32_USB_BCDR &= ~(1 << 15) /* DPPU */;
+#else
+ /* hardwired or regular GPIO on other platforms */
+#endif
+
+ /* power down USB */
+ STM32_USB_CNTR = 0;
+
+ /* disable interrupt handlers */
+ task_disable_irq(STM32_IRQ_USB_LP);
+
+ /* disable 48MHz clock */
+ clock_enable_module(MODULE_USB, 0);
+
+ /* disable USB device clock */
+ STM32_RCC_APB1ENR &= ~STM32_RCC_PB1_USB;
+}
diff --git a/include/config.h b/include/config.h
index 4583146714..535008525c 100644
--- a/include/config.h
+++ b/include/config.h
@@ -949,6 +949,9 @@
/* Compile chip support for the USB device controller */
#undef CONFIG_USB
+/* Disable automatic initialization of USB peripheral */
+#undef CONFIG_USB_INHIBIT
+
/* Support simple control of power to the device's USB ports */
#undef CONFIG_USB_PORT_POWER_DUMB
diff --git a/include/usb.h b/include/usb.h
index 618da651e6..d43450d7cd 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -242,4 +242,8 @@ extern void (*usb_iface_request[]) (usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx);
void IFACE_HANDLER(num)(void) \
__attribute__ ((alias(STRINGIFY(handler))));
+/* functions to start/stop USB */
+void usb_init(void);
+void usb_release(void);
+
#endif /* USB_H */