diff options
-rw-r--r-- | board/hoho/board.c | 71 | ||||
-rw-r--r-- | board/hoho/board.h | 27 | ||||
-rw-r--r-- | include/usb.h | 2 | ||||
-rw-r--r-- | include/usb_pd.h | 2 |
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 |