usbdev: usb device descriptor support USB3.0

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
This commit is contained in:
yangsong8 2024-07-01 18:34:36 +08:00 committed by Alan Carvalho de Assis
parent af017a5c30
commit 0788e68285
11 changed files with 103 additions and 26 deletions

View File

@ -25,6 +25,12 @@ config USBDEV_DUALSPEED
---help--- ---help---
Hardware handles high and full speed operation (USB 2.0) 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 config USBDEV_EPBUFFER_ALIGNMENT
int "The usbdev ep req bffer aligned bytes" int "The usbdev ep req bffer aligned bytes"
default 0 default 0

View File

@ -1627,8 +1627,9 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver,
#ifndef CONFIG_CDCACM_COMPOSITE #ifndef CONFIG_CDCACM_COMPOSITE
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
{ {
ret = USB_SIZEOF_DEVDESC; ret = usbdev_copy_devdesc(ctrlreq->buf,
memcpy(ctrlreq->buf, cdcacm_getdevdesc(), ret); cdcacm_getdevdesc(),
dev->speed);
} }
break; break;
#endif #endif

View File

@ -1463,8 +1463,7 @@ static int cdcecm_getdescriptor(FAR struct cdcecm_driver_s *self,
#ifndef CONFIG_CDCECM_COMPOSITE #ifndef CONFIG_CDCECM_COMPOSITE
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
{ {
memcpy(desc, &g_devdesc, sizeof(g_devdesc)); return usbdev_copy_devdesc(desc, &g_devdesc, self->usbdev.speed);
return (int)sizeof(g_devdesc);
} }
break; break;
#endif #endif
@ -1718,6 +1717,7 @@ static int cdcecm_setup(FAR struct usbdevclass_driver_s *driver,
uint8_t descindex = ctrl->value[0]; uint8_t descindex = ctrl->value[0];
uint8_t desctype = ctrl->value[1]; uint8_t desctype = ctrl->value[1];
self->usbdev.speed = dev->speed;
ret = cdcecm_getdescriptor(self, desctype, descindex, ret = cdcecm_getdescriptor(self, desctype, descindex,
self->ctrlreq->buf); self->ctrlreq->buf);
} }
@ -1835,7 +1835,9 @@ static int cdcecm_classobject(int minor,
/* USB device initialization */ /* 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; self->usbdev.speed = USB_SPEED_HIGH;
#else #else
self->usbdev.speed = USB_SPEED_FULL; self->usbdev.speed = USB_SPEED_FULL;

View File

@ -37,6 +37,7 @@
#include <sys/poll.h> #include <sys/poll.h>
#include <nuttx/net/netdev_lowerhalf.h> #include <nuttx/net/netdev_lowerhalf.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/cdc.h> #include <nuttx/usb/cdc.h>
#include <nuttx/usb/cdcncm.h> #include <nuttx/usb/cdcncm.h>
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
@ -2320,8 +2321,9 @@ static int cdcncm_getdescriptor(FAR struct cdcncm_driver_s *self,
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
if (self->isncm) if (self->isncm)
{ {
memcpy(desc, &g_ncmdevdesc, sizeof(g_ncmdevdesc)); return usbdev_copy_devdesc(desc,
return sizeof(g_ncmdevdesc); &g_ncmdevdesc,
self->usbdev.speed);
} }
# ifdef CONFIG_NET_CDCMBIM # ifdef CONFIG_NET_CDCMBIM
else else
@ -2582,6 +2584,7 @@ static int cdcncm_setup(FAR struct usbdevclass_driver_s *driver,
uint8_t descindex = ctrl->value[0]; uint8_t descindex = ctrl->value[0];
uint8_t desctype = ctrl->value[1]; uint8_t desctype = ctrl->value[1];
self->usbdev.speed = dev->speed;
ret = cdcncm_getdescriptor(self, desctype, descindex, ret = cdcncm_getdescriptor(self, desctype, descindex,
self->ctrlreq->buf); self->ctrlreq->buf);
} }
@ -2791,7 +2794,9 @@ static int cdcncm_classobject(int minor,
/* USB device initialization */ /* 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; self->usbdev.speed = USB_SPEED_HIGH;
#else #else
self->usbdev.speed = USB_SPEED_FULL; self->usbdev.speed = USB_SPEED_FULL;
@ -2866,7 +2871,9 @@ static int cdcmbim_classobject(int minor,
/* USB device initialization */ /* 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; ncm->usbdev.speed = USB_SPEED_HIGH;
#else #else
ncm->usbdev.speed = USB_SPEED_FULL; ncm->usbdev.speed = USB_SPEED_FULL;

View File

@ -643,8 +643,10 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
{ {
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
{ {
ret = USB_SIZEOF_DEVDESC; ret = usbdev_copy_devdesc(ctrlreq->buf,
memcpy(ctrlreq->buf, priv->descs->devdesc, ret); priv->descs->devdesc,
dev->speed);
#ifdef CONFIG_BOARD_USBDEV_PIDVID #ifdef CONFIG_BOARD_USBDEV_PIDVID
{ {
uint16_t pid = board_usbdev_pid(); uint16_t pid = board_usbdev_pid();
@ -1098,14 +1100,15 @@ FAR void *composite_initialize(FAR const struct usbdev_devdescs_s *devdescs,
priv->ndevices = ndevices; priv->ndevices = ndevices;
/* Initialize the USB class driver structure */ /* Initialize the USB class driver structure */
#if defined(CONFIG_USBDEV_SUPERSPEED)
#ifdef CONFIG_USBDEV_DUALSPEED drvr->drvr.speed = USB_SPEED_SUPER;
drvr->drvr.speed = USB_SPEED_HIGH; #elif defined(CONFIG_USBDEV_DUALSPEED)
drvr->drvr.speed = USB_SPEED_HIGH;
#else #else
drvr->drvr.speed = USB_SPEED_FULL; drvr->drvr.speed = USB_SPEED_FULL;
#endif #endif
drvr->drvr.ops = &g_driverops; drvr->drvr.ops = &g_driverops;
drvr->dev = priv; drvr->dev = priv;
/* Register the USB composite class driver */ /* Register the USB composite class driver */

View File

@ -1624,8 +1624,9 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver,
{ {
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
{ {
ret = USB_SIZEOF_DEVDESC; ret = usbdev_copy_devdesc(ctrlreq->buf,
memcpy(ctrlreq->buf, &g_devdesc, ret); &g_devdesc,
dev->speed);
} }
break; break;
@ -2319,7 +2320,9 @@ int usbdev_serialinitialize(int minor)
/* Initialize the USB class driver structure */ /* 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; drvr->drvr.speed = USB_SPEED_HIGH;
#else #else
drvr->drvr.speed = USB_SPEED_FULL; drvr->drvr.speed = USB_SPEED_FULL;

View File

@ -2426,8 +2426,9 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver,
#ifndef CONFIG_RNDIS_COMPOSITE #ifndef CONFIG_RNDIS_COMPOSITE
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
{ {
ret = USB_SIZEOF_DEVDESC; ret = usbdev_copy_devdesc(ctrlreq->buf,
memcpy(ctrlreq->buf, &g_devdesc, ret); &g_devdesc,
dev->speed);
} }
break; break;
#endif #endif
@ -2851,7 +2852,9 @@ static int usbclass_classobject(int minor,
/* Initialize the USB class driver structure */ /* 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; drvr->drvr.speed = USB_SPEED_HIGH;
#else #else
drvr->drvr.speed = USB_SPEED_FULL; drvr->drvr.speed = USB_SPEED_FULL;

View File

@ -32,6 +32,39 @@
* Public Functions * 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 * Name: usbdev_copy_epdesc
* *

View File

@ -513,8 +513,9 @@ static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver,
#ifndef CONFIG_USBMSC_COMPOSITE #ifndef CONFIG_USBMSC_COMPOSITE
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
{ {
ret = USB_SIZEOF_DEVDESC; ret = usbdev_copy_devdesc(ctrlreq->buf,
memcpy(ctrlreq->buf, usbmsc_getdevdesc(), ret); usbmsc_getdevdesc(),
dev->speed);
} }
break; break;
#endif #endif
@ -1296,7 +1297,9 @@ int usbmsc_configure(unsigned int nluns, FAR void **handle)
/* Initialize the USB class driver structure */ /* Initialize the USB class driver structure */
drvr = &alloc->drvr; 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; drvr->drvr.speed = USB_SPEED_HIGH;
#else #else
drvr->drvr.speed = USB_SPEED_FULL; drvr->drvr.speed = USB_SPEED_FULL;

View File

@ -267,6 +267,8 @@
#define USB_SPEED_FULL 2 /* USB 1.1 */ #define USB_SPEED_FULL 2 /* USB 1.1 */
#define USB_SPEED_HIGH 3 /* USB 2.0 */ #define USB_SPEED_HIGH 3 /* USB 2.0 */
#define USB_SPEED_VARIABLE 4 /* Wireless USB 2.5 */ #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 */ /* Maximum number of devices per controller */

View File

@ -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, void usbdev_freereq(FAR struct usbdev_ep_s *ep,
FAR struct usbdev_req_s *req); 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 * Name: usbdev_copy_epdesc
* *