summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Broch <tbroch@chromium.org>2014-10-03 18:12:33 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-11 02:22:36 +0000
commit03cbbb2be714a104f74005774991049e257be996 (patch)
tree8e9d6e66aa8af4b034e15d1383621bd66119c933
parent8a6c72022f1a43fe8288eed2e1a5b94400ca4b1f (diff)
downloadchrome-ec-03cbbb2be714a104f74005774991049e257be996.tar.gz
hoho: Add USB Billboard class device.
BRANCH=none BUG=chrome-os-partner:31192 TEST=manual Plug hoho into samus and see: # lsusb -d 18d1:5010 -v Bus 001 Device 007: ID 18d1:5010 Google Inc. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.01 bDeviceClass 17 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x18d1 Google Inc. idProduct 0x5010 bcdDevice 2.00 iManufacturer 1 Google Inc. iProduct 2 Hoho iSerial 3 v0.001 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 10 bNumInterfaces 0 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 500mA Binary Object Store Descriptor: bLength 5 bDescriptorType 15 wTotalLength 73 bNumDeviceCaps 2 FIXME: alloc bigger buffer for device capability descriptors Device Status: 0x0000 (Bus Powered) Change-Id: I1431829f926eaf86477b49591e9b0adf2b4cb3a6 Signed-off-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/221571 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/hoho/board.c71
-rw-r--r--board/hoho/board.h27
-rw-r--r--include/usb.h2
-rw-r--r--include/usb_pd.h2
4 files changed, 101 insertions, 1 deletions
diff --git a/board/hoho/board.c b/board/hoho/board.c
index 35bd123bc5..598768ee6d 100644
--- a/board/hoho/board.c
+++ b/board/hoho/board.c
@@ -13,6 +13,9 @@
#include "i2c.h"
#include "registers.h"
#include "task.h"
+#include "usb.h"
+#include "usb_bb.h"
+#include "usb_pd.h"
#include "util.h"
#include "gpio_list.h"
@@ -78,3 +81,71 @@ const struct i2c_port_t i2c_ports[] = {
{"master", I2C_PORT_MASTER, 400, GPIO_MCDP_I2C_SCL, GPIO_MCDP_I2C_SDA},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+const void * const usb_strings[] = {
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("Hoho"),
+ [USB_STR_VERSION] = USB_STRING_DESC("v0.001"),
+ [USB_STR_BB_URL] = USB_STRING_DESC(USB_GOOGLE_TYPEC_URL),
+};
+BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
+
+/**
+ * USB configuration
+ * Any type-C device with alternate mode capabilities must have the following
+ * set of descriptors.
+ *
+ * 1. Standard Device
+ * 2. BOS
+ * 2a. Container ID
+ * 2b. Billboard Caps
+ */
+struct my_bos {
+ struct usb_bos_hdr_descriptor bos;
+ struct usb_contid_caps_descriptor contid_caps;
+ struct usb_bb_caps_base_descriptor bb_caps;
+ struct usb_bb_caps_svid_descriptor bb_caps_svids[1];
+};
+
+static struct my_bos bos_desc = {
+ .bos = {
+ .bLength = USB_DT_BOS_SIZE,
+ .bDescriptorType = USB_DT_BOS,
+ .wTotalLength = (USB_DT_BOS_SIZE + USB_DT_CONTID_SIZE +
+ USB_BB_CAPS_BASE_SIZE +
+ USB_BB_CAPS_SVID_SIZE * 1),
+ .bNumDeviceCaps = 2, /* contid + bb_caps */
+ },
+ .contid_caps = {
+ .bLength = USB_DT_CONTID_SIZE,
+ .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
+ .bDevCapabilityType = USB_DC_DTYPE_CONTID,
+ .bReserved = 0,
+ .ContainerID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ },
+ .bb_caps = {
+ .bLength = (USB_BB_CAPS_BASE_SIZE + USB_BB_CAPS_SVID_SIZE * 1),
+ .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
+ .bDevCapabilityType = USB_DC_DTYPE_BILLBOARD,
+ .iAdditionalInfoURL = USB_STR_BB_URL,
+ .bNumberOfAlternateModes = 1,
+ .bPreferredAlternateMode = 1,
+ .VconnPower = 0,
+ .bmConfigured = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ .bReserved = 0,
+ },
+ .bb_caps_svids = {
+ {
+ .wSVID = 0xff01, /* TODO(tbroch) def'd in other CL remove hardcode */
+ .bAlternateMode = 1,
+ .iAlternateModeString = USB_STR_BB_URL, /* TODO(crosbug.com/p/32687) */
+ },
+ },
+};
+
+const struct bos_context bos_ctx = {
+ .descp = (void *)&bos_desc,
+ .size = sizeof(struct my_bos),
+};
diff --git a/board/hoho/board.h b/board/hoho/board.h
index aa53c70849..2bc8e2ab87 100644
--- a/board/hoho/board.h
+++ b/board/hoho/board.h
@@ -25,6 +25,8 @@
#define CONFIG_SPI_FLASH_SIZE 1048576
#define CONFIG_SPI_MASTER_PORT 2
#define CONFIG_SPI_CS_GPIO GPIO_PD_MCDP_SPI_CS_L
+#define CONFIG_USB
+#define CONFIG_USB_BOS
#define CONFIG_USB_POWER_DELIVERY
#define CONFIG_USB_PD_ALT_MODE
#define CONFIG_USB_PD_DUAL_ROLE
@@ -39,6 +41,9 @@
/* I2C ports configuration */
#define I2C_PORT_MASTER 0
+/* USB configuration */
+#define CONFIG_USB_PID 0x5010
+
/*
* Allow dangerous commands all the time, since we don't have a write protect
* switch.
@@ -59,6 +64,28 @@ enum adc_channel {
/* Number of ADC channels */
ADC_CH_COUNT
};
+
+/* USB string indexes */
+enum usb_strings {
+ USB_STR_DESC = 0,
+ USB_STR_VENDOR,
+ USB_STR_PRODUCT,
+ USB_STR_VERSION,
+ USB_STR_BB_URL,
+
+ USB_STR_COUNT
+};
+
#endif /* !__ASSEMBLER__ */
+/* USB Device class */
+#define USB_DEV_CLASS USB_CLASS_BILLBOARD
+
+/* USB interface indexes (use define rather than enum to expand them) */
+#define USB_IFACE_COUNT 0
+
+/* USB endpoint indexes (use define rather than enum to expand them) */
+#define USB_EP_CONTROL 0
+#define USB_EP_COUNT 1
+
#endif /* __BOARD_H */
diff --git a/include/usb.h b/include/usb.h
index 3d63efa60e..ffbdf37c27 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -257,7 +257,7 @@ static inline void memcpy_usbram(usb_uint *ebuf, const uint8_t *src, int size)
/* 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;
+extern const struct bos_context bos_ctx;
/* Helpers for endpoint declaration */
diff --git a/include/usb_pd.h b/include/usb_pd.h
index d96ca9b1fd..8f74e3dd13 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -406,6 +406,8 @@ struct pd_policy {
/* USB-IF SIDs */
#define USB_SID_PD 0xff00 /* power delivery */
#define USB_SID_DISPLAYPORT 0xff01
+
+#define USB_GOOGLE_TYPEC_URL "http://www.google.com/chrome/devices/typec"
/* USB Vendor ID assigned to Google Inc. */
#define USB_VID_GOOGLE 0x18d1