diff options
author | Todd Broch <tbroch@chromium.org> | 2014-10-03 17:22:42 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-10-11 02:22:23 +0000 |
commit | 44e4f7cfe7953198091cfd5e39bf339a770138dc (patch) | |
tree | bce95eac678d68d40be59276b4aaf94a488cea25 | |
parent | 4d81320ed8b5f8231759d1608183a0daf233ea45 (diff) | |
download | chrome-ec-44e4f7cfe7953198091cfd5e39bf339a770138dc.tar.gz |
usb: Groundwork for USB BOS & Billboard class descriptors.
The BOS (Binary Device Object Store) descriptor was added to the USB
specification (3.0) to allow a richer set of device capability
specific descriptors.
The Billboard class is meant to expose (read-only) the status of USB
devices capable of alternate mode functions. It's required to use the
BOS descriptor type and at a high level looks like:
- BOS Device Descriptor (5bytes)
- Container ID Device Capability Descriptor (20bytes)
- Billboard Device Capability Descriptor (44byte + 4 * numSVIDs)
This CL adds:
1. Ability for Get Descriptor on BOS descriptors. Note hidden behind
CONFIG_USB_BOS as these descriptors change USB device requirements
to:
- bcdUSB >= 0201
- no interface descriptors
2. structures for all BOS, Container & Billboard descriptor elements
complete w/ CamelCase.
BRANCH=none
BUG=chrome-os-partner:32652
TEST=compiles with CONFIG_USB & CONFIG_USB_BOS enabled.
Change-Id: I1b24bc728f2ebba7d91840801d2ebe576e240e7c
Signed-off-by: Todd Broch <tbroch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221570
-rw-r--r-- | chip/stm32/usb.c | 21 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | include/usb.h | 46 | ||||
-rw-r--r-- | include/usb_bb.h | 54 |
4 files changed, 124 insertions, 3 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index 6ff00703ff..d4ad8e48ea 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -19,12 +19,23 @@ /* Console output macro */ #define CPRINTF(format, args...) cprintf(CC_USB, format, ## args) +#ifdef CONFIG_USB_BOS +/* v2.01 (vs 2.00) BOS Descriptor provided */ +#define USB_DEV_BCDUSB 0x0201 +#else +#define USB_DEV_BCDUSB 0x0200 +#endif + +#ifndef USB_DEV_CLASS +#define USB_DEV_CLASS USB_CLASS_PER_INTERFACE +#endif + /* USB Standard Device Descriptor */ static const struct usb_device_descriptor dev_desc = { .bLength = USB_DT_DEVICE_SIZE, .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, /* v2.00 */ - .bDeviceClass = USB_CLASS_PER_INTERFACE, + .bcdUSB = USB_DEV_BCDUSB, + .bDeviceClass = USB_DEV_CLASS, .bDeviceSubClass = 0x00, .bDeviceProtocol = 0x00, .bMaxPacketSize0 = USB_MAX_PACKET_SIZE, @@ -100,6 +111,12 @@ static void ep0_rx(void) desc = __usb_desc; len = USB_DESC_SIZE; break; +#ifdef CONFIG_USB_BOS + case USB_DT_BOS: /* Setup : Get BOS descriptor */ + desc = bos_ctx.descp; + len = bos_ctx.size; + break; +#endif case USB_DT_STRING: /* Setup : Get string descriptor */ if (idx >= USB_STR_COUNT) /* The string does not exist : STALL */ diff --git a/include/config.h b/include/config.h index 3183e3b267..2cc2b0f93a 100644 --- a/include/config.h +++ b/include/config.h @@ -1041,6 +1041,12 @@ /* Support for USB type-c superspeed mux */ #undef CONFIG_USBC_SS_MUX +/* Support for USB type-c vconn. Not needed for captive cables. */ +#undef CONFIG_USBC_VCONN + +/* USB Binary device Object Store support */ +#undef CONFIG_USB_BOS + /*****************************************************************************/ /* USB interfaces config */ diff --git a/include/usb.h b/include/usb.h index d43450d7cd..3d63efa60e 100644 --- a/include/usb.h +++ b/include/usb.h @@ -24,6 +24,8 @@ #define USB_DT_OTHER_SPEED_CONFIG 0x07 #define USB_DT_INTERFACE_POWER 0x08 #define USB_DT_DEBUG 0x0a +#define USB_DT_BOS 0x0f +#define USB_DT_DEVICE_CAPABILITY 0x10 /* USB Device Descriptor */ struct usb_device_descriptor { @@ -44,6 +46,46 @@ struct usb_device_descriptor { } __packed; #define USB_DT_DEVICE_SIZE 18 +/* BOS Descriptor ( USB3.1 rev1 Section 9.6.2 ) */ +struct bos_context { + void *descp; + int size; +}; + +struct usb_bos_hdr_descriptor { + uint8_t bLength; + uint8_t bDescriptorType; /* USB_DT_BOS */ + uint16_t wTotalLength; /* Total length of of hdr + all dev caps */ + uint8_t bNumDeviceCaps; /* Container ID Descriptor + others */ +} __packed; +#define USB_DT_BOS_SIZE 5 + +/* Container ID Descriptor */ +struct usb_contid_caps_descriptor { + uint8_t bLength; + uint8_t bDescriptorType; /* USB_DT_DEVICE_CAPABILITY */ + uint8_t bDevCapabilityType; /* USB_DC_DTYPE_xxx */ + uint8_t bReserved; /* SBZ */ + uint8_t ContainerID[16]; /* UUID */ +} __packed; +#define USB_DT_CONTID_SIZE 20 + +/* Device Cap Type Codes ( offset 2 of Device Capability Descriptor */ +#define USB_DC_DTYPE_WIRELESS 0x01 +#define USB_DC_DTYPE_USB20EXT 0x02 +#define USB_DC_DTYPE_USBSS 0x03 +#define USB_DC_DTYPE_CONTID 0x04 +#define USB_DC_DTYPE_PLATFORM 0x05 +#define USB_DC_DTYPE_PD 0x06 +#define USB_DC_DTYPE_BATTINFO 0x07 +#define USB_DC_DTYPE_CONSUMER 0x08 +#define USB_DC_DTYPE_PRODUCER 0x09 +#define USB_DC_DTYPE_USBSSP 0x0a +#define USB_DC_DTYPE_PCSTIME 0x0b +#define USB_DC_DTYPE_WUSBEXT 0x0c +#define USB_DC_DTYPE_BILLBOARD 0x0d +/* RESERVED 0x00, 0xOe - 0xff */ + /* Configuration Descriptor */ struct usb_config_descriptor { uint8_t bLength; @@ -103,6 +145,7 @@ struct usb_endpoint_descriptor { #define USB_CLASS_CSCID 0x0b #define USB_CLASS_CONTENT_SEC 0x0d #define USB_CLASS_VIDEO 0x0e +#define USB_CLASS_BILLBOARD 0x11 #define USB_CLASS_WIRELESS_CONTROLLER 0xe0 #define USB_CLASS_MISC 0xef #define USB_CLASS_APP_SPEC 0xfe @@ -211,9 +254,10 @@ static inline void memcpy_usbram(usb_uint *ebuf, const uint8_t *src, int size) (((uint32_t)(x) - (uint32_t)__usb_ram_start) \ / (sizeof(usb_uint)/sizeof(uint16_t))) -/* String descriptors are defined in the board code */ +/* These descriptors defined in board code */ extern const void * const usb_strings[]; extern const uint8_t usb_string_desc[]; +extern struct bos_context bos_ctx; /* Helpers for endpoint declaration */ diff --git a/include/usb_bb.h b/include/usb_bb.h new file mode 100644 index 0000000000..56864a6a1d --- /dev/null +++ b/include/usb_bb.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * USB billboard definitions. + */ + +#ifndef USB_BB_H +#define USB_BB_H + +/* per Billboard Device Class Spec Revision 1.0 */ + +/* device descriptor fields */ +#define USB_BB_BCDUSB_MIN 0x0201 /* v2.01 minimum */ +#define USB_BB_SUBCLASS 0x00 +#define USB_BB_PROTOCOL 0x00 +#define USB_BB_EP0_PACKET_SIZE 8 +#define USB_BB_CAP_DESC_TYPE 0x0d + + +#define USB_BB_CAPS_SVID_SIZE 4 +struct usb_bb_caps_svid_descriptor { + uint16_t wSVID; + uint8_t bAlternateMode; + uint8_t iAlternateModeString; +} __packed; + +#define USB_BB_CAPS_BASE_SIZE 44 +struct usb_bb_caps_base_descriptor { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bDevCapabilityType; + uint8_t iAdditionalInfoURL; + uint8_t bNumberOfAlternateModes; + uint8_t bPreferredAlternateMode; + uint16_t VconnPower; + uint8_t bmConfigured[32]; /* 2b per SVID w/ 128 SVIDs allowed. */ + uint32_t bReserved; /* SBZ */ +} __packed; + + +#define USB_BB_VCONN_PWRON(x) (x << 15) +#define USB_BB_VCONN_PWR_1W 0 +#define USB_BB_VCONN_PWR_1p5W 1 +#define USB_BB_VCONN_PWR_2W 2 +#define USB_BB_VCONN_PWR_3W 3 +#define USB_BB_VCONN_PWR_4W 4 +#define USB_BB_VCONN_PWR_5W 5 +#define USB_BB_VCONN_PWR_6W 6 +/* Note, 7W (111b) is reserved */ + + +#endif /* USB_BB_H */ + |