diff --git a/drivers/usbdev/Kconfig b/drivers/usbdev/Kconfig index 1573f47653..5e7573529d 100644 --- a/drivers/usbdev/Kconfig +++ b/drivers/usbdev/Kconfig @@ -25,6 +25,12 @@ config USBDEV_DUALSPEED ---help--- Hardware handles high and full speed operation (USB 2.0) +config USBDEV_SUPERSPEED + bool "Enable super speed" + default n + ---help--- + Hardware handles super speed operation (USB 3.2) + config USBDEV_EPBUFFER_ALIGNMENT int "The usbdev ep req bffer aligned bytes" default 0 diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index fa22e5b249..7f887bd8be 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -1627,8 +1627,9 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, #ifndef CONFIG_CDCACM_COMPOSITE case USB_DESC_TYPE_DEVICE: { - ret = USB_SIZEOF_DEVDESC; - memcpy(ctrlreq->buf, cdcacm_getdevdesc(), ret); + ret = usbdev_copy_devdesc(ctrlreq->buf, + cdcacm_getdevdesc(), + dev->speed); } break; #endif diff --git a/drivers/usbdev/cdcecm.c b/drivers/usbdev/cdcecm.c index a222910f99..1ec84309ed 100644 --- a/drivers/usbdev/cdcecm.c +++ b/drivers/usbdev/cdcecm.c @@ -1463,8 +1463,7 @@ static int cdcecm_getdescriptor(FAR struct cdcecm_driver_s *self, #ifndef CONFIG_CDCECM_COMPOSITE case USB_DESC_TYPE_DEVICE: { - memcpy(desc, &g_devdesc, sizeof(g_devdesc)); - return (int)sizeof(g_devdesc); + return usbdev_copy_devdesc(desc, &g_devdesc, self->usbdev.speed); } break; #endif @@ -1718,6 +1717,7 @@ static int cdcecm_setup(FAR struct usbdevclass_driver_s *driver, uint8_t descindex = ctrl->value[0]; uint8_t desctype = ctrl->value[1]; + self->usbdev.speed = dev->speed; ret = cdcecm_getdescriptor(self, desctype, descindex, self->ctrlreq->buf); } @@ -1835,7 +1835,9 @@ static int cdcecm_classobject(int minor, /* USB device initialization */ -#ifdef CONFIG_USBDEV_DUALSPEED +#if defined(CONFIG_USBDEV_SUPERSPEED) + self->usbdev.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) self->usbdev.speed = USB_SPEED_HIGH; #else self->usbdev.speed = USB_SPEED_FULL; diff --git a/drivers/usbdev/cdcncm.c b/drivers/usbdev/cdcncm.c index cf7974bd16..3c40f881d4 100644 --- a/drivers/usbdev/cdcncm.c +++ b/drivers/usbdev/cdcncm.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -2320,8 +2321,9 @@ static int cdcncm_getdescriptor(FAR struct cdcncm_driver_s *self, case USB_DESC_TYPE_DEVICE: if (self->isncm) { - memcpy(desc, &g_ncmdevdesc, sizeof(g_ncmdevdesc)); - return sizeof(g_ncmdevdesc); + return usbdev_copy_devdesc(desc, + &g_ncmdevdesc, + self->usbdev.speed); } # ifdef CONFIG_NET_CDCMBIM else @@ -2582,6 +2584,7 @@ static int cdcncm_setup(FAR struct usbdevclass_driver_s *driver, uint8_t descindex = ctrl->value[0]; uint8_t desctype = ctrl->value[1]; + self->usbdev.speed = dev->speed; ret = cdcncm_getdescriptor(self, desctype, descindex, self->ctrlreq->buf); } @@ -2791,7 +2794,9 @@ static int cdcncm_classobject(int minor, /* USB device initialization */ -#ifdef CONFIG_USBDEV_DUALSPEED +#if defined(CONFIG_USBDEV_SUPERSPEED) + self->usbdev.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) self->usbdev.speed = USB_SPEED_HIGH; #else self->usbdev.speed = USB_SPEED_FULL; @@ -2866,7 +2871,9 @@ static int cdcmbim_classobject(int minor, /* USB device initialization */ -#ifdef CONFIG_USBDEV_DUALSPEED +#if defined(CONFIG_USBDEV_SUPERSPEED) + ncm->usbdev.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) ncm->usbdev.speed = USB_SPEED_HIGH; #else ncm->usbdev.speed = USB_SPEED_FULL; diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index e99844df0a..8e3f990f1c 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -643,8 +643,10 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, { case USB_DESC_TYPE_DEVICE: { - ret = USB_SIZEOF_DEVDESC; - memcpy(ctrlreq->buf, priv->descs->devdesc, ret); + ret = usbdev_copy_devdesc(ctrlreq->buf, + priv->descs->devdesc, + dev->speed); + #ifdef CONFIG_BOARD_USBDEV_PIDVID { uint16_t pid = board_usbdev_pid(); @@ -1098,14 +1100,15 @@ FAR void *composite_initialize(FAR const struct usbdev_devdescs_s *devdescs, priv->ndevices = ndevices; /* Initialize the USB class driver structure */ - -#ifdef CONFIG_USBDEV_DUALSPEED - drvr->drvr.speed = USB_SPEED_HIGH; +#if defined(CONFIG_USBDEV_SUPERSPEED) + drvr->drvr.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) + drvr->drvr.speed = USB_SPEED_HIGH; #else - drvr->drvr.speed = USB_SPEED_FULL; + drvr->drvr.speed = USB_SPEED_FULL; #endif - drvr->drvr.ops = &g_driverops; - drvr->dev = priv; + drvr->drvr.ops = &g_driverops; + drvr->dev = priv; /* Register the USB composite class driver */ diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index 032eed5ec7..116ff8489c 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -1624,8 +1624,9 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, { case USB_DESC_TYPE_DEVICE: { - ret = USB_SIZEOF_DEVDESC; - memcpy(ctrlreq->buf, &g_devdesc, ret); + ret = usbdev_copy_devdesc(ctrlreq->buf, + &g_devdesc, + dev->speed); } break; @@ -2319,7 +2320,9 @@ int usbdev_serialinitialize(int minor) /* Initialize the USB class driver structure */ -#ifdef CONFIG_USBDEV_DUALSPEED +#if defined(CONFIG_USBDEV_SUPERSPEED) + drvr->drvr.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) drvr->drvr.speed = USB_SPEED_HIGH; #else drvr->drvr.speed = USB_SPEED_FULL; diff --git a/drivers/usbdev/rndis.c b/drivers/usbdev/rndis.c index 2d189d144c..50ec804ab5 100644 --- a/drivers/usbdev/rndis.c +++ b/drivers/usbdev/rndis.c @@ -2426,8 +2426,9 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, #ifndef CONFIG_RNDIS_COMPOSITE case USB_DESC_TYPE_DEVICE: { - ret = USB_SIZEOF_DEVDESC; - memcpy(ctrlreq->buf, &g_devdesc, ret); + ret = usbdev_copy_devdesc(ctrlreq->buf, + &g_devdesc, + dev->speed); } break; #endif @@ -2851,7 +2852,9 @@ static int usbclass_classobject(int minor, /* Initialize the USB class driver structure */ -#ifdef CONFIG_USBDEV_DUALSPEED +#if defined(CONFIG_USBDEV_SUPERSPEED) + drvr->drvr.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) drvr->drvr.speed = USB_SPEED_HIGH; #else drvr->drvr.speed = USB_SPEED_FULL; diff --git a/drivers/usbdev/usbdev_desc.c b/drivers/usbdev/usbdev_desc.c index bf065d07ef..f9c12e8274 100644 --- a/drivers/usbdev/usbdev_desc.c +++ b/drivers/usbdev/usbdev_desc.c @@ -32,6 +32,39 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: usbdev_copy_devdesc + * + * Description: + * Copies the requested device Description into the dest buffer given. + * Returns the number of Bytes filled in (USB_SIZEOF_DEVDESC). + * This function is provided by various classes. + * + ****************************************************************************/ + +int usbdev_copy_devdesc(FAR void *dest, + FAR const struct usb_devdesc_s *src, + uint8_t speed) +{ +#ifdef CONFIG_USBDEV_SUPERSPEED + FAR struct usb_devdesc_s *p_desc = + (struct usb_devdesc_s *)dest; +#endif + + memcpy(dest, src, USB_SIZEOF_DEVDESC); + +#ifdef CONFIG_USBDEV_SUPERSPEED + if (speed >= USB_SPEED_SUPER) + { + p_desc->usb[0] = LSBYTE(0x0320), + p_desc->usb[1] = MSBYTE(0x0320); + p_desc->mxpacketsize = 9; + } +#endif + + return USB_SIZEOF_DEVDESC; +} + /**************************************************************************** * Name: usbdev_copy_epdesc * diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 524cb818d8..8298a0af0c 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -513,8 +513,9 @@ static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver, #ifndef CONFIG_USBMSC_COMPOSITE case USB_DESC_TYPE_DEVICE: { - ret = USB_SIZEOF_DEVDESC; - memcpy(ctrlreq->buf, usbmsc_getdevdesc(), ret); + ret = usbdev_copy_devdesc(ctrlreq->buf, + usbmsc_getdevdesc(), + dev->speed); } break; #endif @@ -1296,7 +1297,9 @@ int usbmsc_configure(unsigned int nluns, FAR void **handle) /* Initialize the USB class driver structure */ drvr = &alloc->drvr; -#ifdef CONFIG_USBDEV_DUALSPEED +#if defined(CONFIG_USBDEV_SUPERSPEED) + drvr->drvr.speed = USB_SPEED_SUPER; +#elif defined(CONFIG_USBDEV_DUALSPEED) drvr->drvr.speed = USB_SPEED_HIGH; #else drvr->drvr.speed = USB_SPEED_FULL; diff --git a/include/nuttx/usb/usb.h b/include/nuttx/usb/usb.h index 56c17043c7..d9286bcebf 100644 --- a/include/nuttx/usb/usb.h +++ b/include/nuttx/usb/usb.h @@ -267,6 +267,8 @@ #define USB_SPEED_FULL 2 /* USB 1.1 */ #define USB_SPEED_HIGH 3 /* USB 2.0 */ #define USB_SPEED_VARIABLE 4 /* Wireless USB 2.5 */ +#define USB_SPEED_SUPER 5 /* usb 3.0 */ +#define USB_SPEED_SUPER_PLUS 6 /* usb 3.1 */ /* Maximum number of devices per controller */ diff --git a/include/nuttx/usb/usbdev.h b/include/nuttx/usb/usbdev.h index 07f3dbe40c..557e1e3724 100644 --- a/include/nuttx/usb/usbdev.h +++ b/include/nuttx/usb/usbdev.h @@ -413,6 +413,20 @@ FAR struct usbdev_req_s *usbdev_allocreq(FAR struct usbdev_ep_s *ep, void usbdev_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req); +/**************************************************************************** + * Name: usbdev_copy_devdesc + * + * Description: + * Copies the requested device Description into the dest buffer given. + * Returns the number of Bytes filled in (USB_SIZEOF_DEVDESC). + * This function is provided by various classes. + * + ****************************************************************************/ + +int usbdev_copy_devdesc(FAR void *dest, + FAR const struct usb_devdesc_s *src, + uint8_t speed); + /**************************************************************************** * Name: usbdev_copy_epdesc *