summaryrefslogtreecommitdiff
path: root/chip/stm32/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip/stm32/usb.c')
-rw-r--r--chip/stm32/usb.c130
1 files changed, 61 insertions, 69 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c
index a1f60e8906..1c621a32b3 100644
--- a/chip/stm32/usb.c
+++ b/chip/stm32/usb.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -21,7 +21,7 @@
#include "usb_hw.h"
/* Console output macro */
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USB, format, ##args)
#ifdef CONFIG_USB_BOS
/* v2.10 (vs 2.00) BOS Descriptor provided */
@@ -73,11 +73,11 @@ const struct usb_config_descriptor USB_CONF_DESC(conf) = {
.bConfigurationValue = 1,
.iConfiguration = USB_STR_VERSION,
.bmAttributes = 0x80 /* Reserved bit */
-#ifdef CONFIG_USB_SELF_POWERED /* bus or self powered */
- | 0x40
+#ifdef CONFIG_USB_SELF_POWERED /* bus or self powered */
+ | 0x40
#endif
#ifdef CONFIG_USB_REMOTE_WAKEUP
- | 0x20
+ | 0x20
#endif
,
.bMaxPower = (CONFIG_USB_MAXPOWER_MA / 2),
@@ -85,8 +85,7 @@ const struct usb_config_descriptor USB_CONF_DESC(conf) = {
const uint8_t usb_string_desc[] = {
4, /* Descriptor size */
- USB_DT_STRING,
- 0x09, 0x04 /* LangID = 0x0409: U.S. English */
+ USB_DT_STRING, 0x09, 0x04 /* LangID = 0x0409: U.S. English */
};
#ifdef CONFIG_USB_MS_EXTENDED_COMPAT_ID_DESCRIPTOR
@@ -95,7 +94,8 @@ const uint8_t usb_string_desc[] = {
* descriptor is used by Windows OS to know to request a Windows Compatible ID
* OS Descriptor so that Windows will load the proper WINUSB driver.
*/
-const void *const usb_ms_os_string_descriptor = {USB_MS_STRING_DESC("MSFT100")};
+const void *const usb_ms_os_string_descriptor = { USB_MS_STRING_DESC(
+ "MSFT100") };
/*
* Extended Compat ID OS Feature descriptor. This descriptor is used by Windows
@@ -125,7 +125,7 @@ struct stm32_endpoint btable_ep[USB_EP_COUNT] __aligned(8) __usb_btable;
static usb_uint ep0_buf_tx[USB_MAX_PACKET_SIZE / 2] __usb_ram;
static usb_uint ep0_buf_rx[USB_MAX_PACKET_SIZE / 2] __usb_ram;
-#define EP0_BUF_TX_SRAM_ADDR ((void *) usb_sram_addr(ep0_buf_tx))
+#define EP0_BUF_TX_SRAM_ADDR ((void *)usb_sram_addr(ep0_buf_tx))
static int set_addr;
/* remaining size of descriptor data to transfer */
@@ -142,10 +142,10 @@ static int remote_wakeup_enabled;
void usb_read_setup_packet(usb_uint *buffer, struct usb_setup_packet *packet)
{
packet->bmRequestType = buffer[0] & 0xff;
- packet->bRequest = buffer[0] >> 8;
- packet->wValue = buffer[1];
- packet->wIndex = buffer[2];
- packet->wLength = buffer[3];
+ packet->bRequest = buffer[0] >> 8;
+ packet->wValue = buffer[1];
+ packet->wIndex = buffer[2];
+ packet->wLength = buffer[3];
}
struct usb_descriptor_patch {
@@ -155,8 +155,8 @@ struct usb_descriptor_patch {
static struct usb_descriptor_patch desc_patches[USB_DESC_PATCH_COUNT];
-void set_descriptor_patch(enum usb_desc_patch_type type,
- const void *address, uint16_t data)
+void set_descriptor_patch(enum usb_desc_patch_type type, const void *address,
+ uint16_t data)
{
desc_patches[type].address = address;
desc_patches[type].data = data;
@@ -176,7 +176,8 @@ void *memcpy_to_usbram_ep0_patch(const void *src, size_t n)
continue;
memcpy_to_usbram((void *)(usb_sram_addr(ep0_buf_tx) + offset),
- &desc_patches[i].data, sizeof(desc_patches[i].data));
+ &desc_patches[i].data,
+ sizeof(desc_patches[i].data));
}
return ret;
@@ -246,7 +247,7 @@ static void ep0_rx(void)
#ifdef CONFIG_USB_MS_EXTENDED_COMPAT_ID_DESCRIPTOR
if (b_req == USB_MS_STRING_DESC_VENDOR_CODE &&
- w_index == USB_MS_EXT_COMPATIBLE_ID_INDEX) {
+ w_index == USB_MS_EXT_COMPATIBLE_ID_INDEX) {
ep0_send_descriptor((uint8_t *)&winusb_desc,
winusb_desc.dwLength, 0);
return;
@@ -310,8 +311,9 @@ static void ep0_rx(void)
default: /* unhandled descriptor */
goto unknown_req;
}
- ep0_send_descriptor(desc, len, type == USB_DT_CONFIGURATION ?
- USB_DESC_SIZE : 0);
+ ep0_send_descriptor(
+ desc, len,
+ type == USB_DT_CONFIGURATION ? USB_DESC_SIZE : 0);
} else if (req == (USB_DIR_IN | (USB_REQ_GET_STATUS << 8))) {
uint16_t data = 0;
/* Get status */
@@ -325,14 +327,14 @@ static void ep0_rx(void)
memcpy_to_usbram(EP0_BUF_TX_SRAM_ADDR, (void *)&data, 2);
btable_ep[0].tx_count = 2;
STM32_TOGGLE_EP(0, EP_TX_RX_MASK, EP_TX_RX_VALID,
- EP_STATUS_OUT /*null OUT transaction */);
+ EP_STATUS_OUT /*null OUT transaction */);
} else if ((req & 0xff) == USB_DIR_OUT) {
switch (req >> 8) {
case USB_REQ_SET_FEATURE:
case USB_REQ_CLEAR_FEATURE:
#ifdef CONFIG_USB_REMOTE_WAKEUP
if (ep0_buf_rx[1] ==
- USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP) {
+ USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP) {
remote_wakeup_enabled =
((req >> 8) == USB_REQ_SET_FEATURE);
btable_ep[0].tx_count = 0;
@@ -407,13 +409,12 @@ static void ep0_event(enum usb_ep_event evt)
if (evt != USB_EVENT_RESET)
return;
- STM32_USB_EP(0) = BIT(9) /* control EP */ |
- (2 << 4) /* TX NAK */ |
+ STM32_USB_EP(0) = BIT(9) /* control EP */ | (2 << 4) /* TX NAK */ |
(3 << 12) /* RX VALID */;
btable_ep[0].tx_addr = usb_sram_addr(ep0_buf_tx);
btable_ep[0].rx_addr = usb_sram_addr(ep0_buf_rx);
- btable_ep[0].rx_count = 0x8000 | ((USB_MAX_PACKET_SIZE/32-1) << 10);
+ btable_ep[0].rx_count = 0x8000 | ((USB_MAX_PACKET_SIZE / 32 - 1) << 10);
btable_ep[0].tx_count = 0;
}
USB_DECLARE_EP(0, ep0_tx, ep0_rx, ep0_event);
@@ -473,8 +474,8 @@ static volatile int sof_received;
static void usb_resume_deferred(void)
{
- uint32_t state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK)
- >> STM32_USB_FNR_RXDP_RXDM_SHIFT;
+ uint32_t state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK) >>
+ STM32_USB_FNR_RXDP_RXDM_SHIFT;
CPRINTF("RSMd %d %04x %d\n", state, STM32_USB_CNTR, sof_received);
if (sof_received == 0 && (state == 2 || state == 3))
@@ -496,8 +497,8 @@ static void usb_resume(void)
/* USB is in use again */
disable_sleep(SLEEP_MASK_USB_DEVICE);
- state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK)
- >> STM32_USB_FNR_RXDP_RXDM_SHIFT;
+ state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK) >>
+ STM32_USB_FNR_RXDP_RXDM_SHIFT;
CPRINTF("RSM %d %04x\n", state, STM32_USB_CNTR);
@@ -534,8 +535,7 @@ static volatile int usb_wake_done = 1;
*/
static volatile int esof_count;
-__attribute__((weak))
-void board_usb_wake(void)
+__attribute__((weak)) void board_usb_wake(void)
{
/* Side-band USB wake, do nothing by default. */
}
@@ -598,8 +598,8 @@ void usb_wake(void)
/* STM32_USB_CNTR can also be updated from interrupt context. */
interrupt_disable();
- STM32_USB_CNTR |= STM32_USB_CNTR_RESUME |
- STM32_USB_CNTR_ESOFM | STM32_USB_CNTR_SOFM;
+ STM32_USB_CNTR |= STM32_USB_CNTR_RESUME | STM32_USB_CNTR_ESOFM |
+ STM32_USB_CNTR_SOFM;
interrupt_enable();
/* Try side-band wake as well. */
@@ -654,8 +654,8 @@ static void usb_interrupt_handle_wake(uint16_t status)
STM32_USB_CNTR &= ~STM32_USB_CNTR_RESUME;
/* Then count down until state is resumed. */
- state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK)
- >> STM32_USB_FNR_RXDP_RXDM_SHIFT;
+ state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK) >>
+ STM32_USB_FNR_RXDP_RXDM_SHIFT;
/*
* state 2, or receiving an SOF, means resume
@@ -670,13 +670,13 @@ static void usb_interrupt_handle_wake(uint16_t status)
STM32_USB_CNTR &= ~STM32_USB_CNTR_ESOFM;
usb_wake_done = 1;
if (!good) {
- CPRINTF("wake error: cnt=%d state=%d\n",
- esof_count, state);
+ CPRINTF("wake error: cnt=%d state=%d\n", esof_count,
+ state);
usb_suspend();
return;
}
- CPRINTF("RSMOK%d %d\n", -esof_count, state);
+ CPRINTF("RSMOK%d %d\n", -esof_count, state);
for (ep = 1; ep < USB_EP_COUNT; ep++)
usb_ep_event[ep](USB_EVENT_DEVICE_RESUME);
@@ -703,7 +703,7 @@ static void usb_interrupt(void)
#ifdef CONFIG_USB_REMOTE_WAKEUP
if (status & (STM32_USB_ISTR_ESOF | STM32_USB_ISTR_SOF) &&
- !usb_wake_done)
+ !usb_wake_done)
usb_interrupt_handle_wake(status);
#endif
@@ -759,12 +759,10 @@ void usb_init(void)
/* Enable interrupt handlers */
task_enable_irq(STM32_IRQ_USB_LP);
/* set interrupts mask : reset/correct transfer/errors */
- STM32_USB_CNTR = STM32_USB_CNTR_CTRM |
- STM32_USB_CNTR_PMAOVRM |
+ STM32_USB_CNTR = STM32_USB_CNTR_CTRM | STM32_USB_CNTR_PMAOVRM |
STM32_USB_CNTR_ERRM |
#ifdef CONFIG_USB_SUSPEND
- STM32_USB_CNTR_WKUPM |
- STM32_USB_CNTR_SUSPM |
+ STM32_USB_CNTR_WKUPM | STM32_USB_CNTR_SUSPM |
#endif
STM32_USB_CNTR_RESETM;
@@ -809,10 +807,10 @@ int usb_is_enabled(void)
void *memcpy_to_usbram(void *dest, const void *src, size_t n)
{
- int unaligned = (((uintptr_t) dest) & 1);
- usb_uint *d = &__usb_ram_start[((uintptr_t) dest) / 2];
- uint8_t *s = (uint8_t *) src;
- int i;
+ int unaligned = (((uintptr_t)dest) & 1);
+ usb_uint *d = &__usb_ram_start[((uintptr_t)dest) / 2];
+ uint8_t *s = (uint8_t *)src;
+ int i;
/*
* Handle unaligned leading byte via read/modify/write.
@@ -839,10 +837,10 @@ void *memcpy_to_usbram(void *dest, const void *src, size_t n)
void *memcpy_from_usbram(void *dest, const void *src, size_t n)
{
- int unaligned = (((uintptr_t) src) & 1);
- usb_uint const *s = &__usb_ram_start[((uintptr_t) src) / 2];
- uint8_t *d = (uint8_t *) dest;
- int i;
+ int unaligned = (((uintptr_t)src) & 1);
+ usb_uint const *s = &__usb_ram_start[((uintptr_t)src) / 2];
+ uint8_t *d = (uint8_t *)dest;
+ int i;
if (unaligned && n) {
*d = *s >> 8;
@@ -923,7 +921,7 @@ static int usb_save_serial(const char *serialno)
return rv;
}
-static int command_serialno(int argc, char **argv)
+static int command_serialno(int argc, const char **argv)
{
struct usb_string_desc *sd = usb_serialno_desc;
char buf[CONFIG_SERIALNO_LEN];
@@ -931,12 +929,10 @@ static int command_serialno(int argc, char **argv)
int i;
if (argc != 1) {
- if ((strcasecmp(argv[1], "set") == 0) &&
- (argc == 3)) {
+ if ((strcasecmp(argv[1], "set") == 0) && (argc == 3)) {
ccprintf("Saving serial number\n");
rv = usb_save_serial(argv[2]);
- } else if ((strcasecmp(argv[1], "load") == 0) &&
- (argc == 2)) {
+ } else if ((strcasecmp(argv[1], "load") == 0) && (argc == 2)) {
ccprintf("Loading serial number\n");
rv = usb_load_serial();
} else
@@ -949,11 +945,10 @@ static int command_serialno(int argc, char **argv)
return rv;
}
-DECLARE_CONSOLE_COMMAND(serialno, command_serialno,
- "load/set [value]",
- "Read and write USB serial number");
+DECLARE_CONSOLE_COMMAND(serialno, command_serialno, "load/set [value]",
+ "Read and write USB serial number");
-#endif /* CONFIG_USB_SERIALNO */
+#endif /* CONFIG_USB_SERIALNO */
#ifdef CONFIG_MAC_ADDR
@@ -980,18 +975,16 @@ static int usb_save_mac_addr(const char *mac_addr)
}
}
-static int command_macaddr(int argc, char **argv)
+static int command_macaddr(int argc, const char **argv)
{
- const char* buf;
+ const char *buf;
int rv = EC_SUCCESS;
if (argc != 1) {
- if ((strcasecmp(argv[1], "set") == 0) &&
- (argc == 3)) {
+ if ((strcasecmp(argv[1], "set") == 0) && (argc == 3)) {
ccprintf("Saving MAC address\n");
rv = usb_save_mac_addr(argv[2]);
- } else if ((strcasecmp(argv[1], "load") == 0) &&
- (argc == 2)) {
+ } else if ((strcasecmp(argv[1], "load") == 0) && (argc == 2)) {
ccprintf("Loading MAC address\n");
} else {
return EC_ERROR_INVAL;
@@ -1006,8 +999,7 @@ static int command_macaddr(int argc, char **argv)
return rv;
}
-DECLARE_CONSOLE_COMMAND(macaddr, command_macaddr,
- "load/set [value]",
- "Read and write MAC address");
+DECLARE_CONSOLE_COMMAND(macaddr, command_macaddr, "load/set [value]",
+ "Read and write MAC address");
-#endif /* CONFIG_MAC_ADDR */
+#endif /* CONFIG_MAC_ADDR */