USB hub: First steps to make interfaces backward compatible

This commit is contained in:
Gregory Nutt
2015-04-20 07:45:11 -06:00
parent 8c1c365ae7
commit a6d9f0622c
4 changed files with 208 additions and 325 deletions
+5 -1
View File
@@ -40,12 +40,16 @@ ifeq ($(CONFIG_USBHOST),y)
# Include built-in USB host driver logic
CSRCS += usbhost_registry.c usbhost_registerclass.c usbhost_findclass.c
CSRCS += usbhost_enumerate.c usbhost_storage.c usbhost_devaddr.c
CSRCS += usbhost_enumerate.c usbhost_devaddr.c
ifeq ($(CONFIG_USBHOST_HUB),y)
CSRCS += usbhost_hub.c
endif
ifeq ($(CONFIG_USBHOST_MSC),y)
CSRCS += usbhost_storage.c
endif
ifeq ($(CONFIG_USBHOST_HIDKBD),y)
CSRCS += usbhost_hidkbd.c
endif
+8 -98
View File
@@ -67,8 +67,6 @@
static inline uint16_t usbhost_getle16(const uint8_t *val);
static void usbhost_putle16(uint8_t *dest, uint16_t val);
static void usbhost_callback(FAR struct usbhost_transfer_s *xfer);
static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc,
FAR struct usbhost_id_s *id);
static inline int usbhost_configdesc(const uint8_t *configdesc, int desclen,
@@ -116,19 +114,6 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val)
dest[1] = val >> 8;
}
/****************************************************************************
* Name: usbhost_callback
*
* Description:
*
*
*******************************************************************************/
static void usbhost_callback(FAR struct usbhost_transfer_s *xfer)
{
sem_post(&xfer->done);
}
/*******************************************************************************
* Name: usbhost_devdesc
*
@@ -173,8 +158,8 @@ static inline int usbhost_devdesc(FAR const struct usb_devdesc_s *devdesc,
static inline int usbhost_configdesc(const uint8_t *configdesc, int cfglen,
struct usbhost_id_s *id)
{
struct usb_cfgdesc_s *cfgdesc;
struct usb_ifdesc_s *ifdesc;
FAR struct usb_cfgdesc_s *cfgdesc;
FAR struct usb_ifdesc_s *ifdesc;
int remaining;
DEBUGASSERT(configdesc != NULL && cfglen >= USB_SIZEOF_CFGDESC);
@@ -392,7 +377,7 @@ int usbhost_enumerate(FAR struct usbhost_class_s *devclass)
usbhost_putle16(ctrlreq->index, 0);
usbhost_putle16(ctrlreq->len, descsize);
ret = usbhost_ctrlxfer(devclass, ctrlreq, buffer);
ret = DRVR_CTRLIN(devclass->drvr, ctrlreq, buffer);
if (ret != OK)
{
udbg("ERROR: Failed to get device descriptor, length=%d: %d\n",
@@ -417,7 +402,7 @@ int usbhost_enumerate(FAR struct usbhost_class_s *devclass)
usbhost_putle16(ctrlreq->index, 0);
usbhost_putle16(ctrlreq->len, 0);
ret = usbhost_ctrlxfer(devclass, ctrlreq, NULL);
ret = DRVR_CTRLOUT(devclass->drvr, ctrlreq, NULL);
if (ret != OK)
{
udbg("ERROR: Failed to set address: %d\n");
@@ -441,7 +426,7 @@ int usbhost_enumerate(FAR struct usbhost_class_s *devclass)
usbhost_putle16(ctrlreq->index, 0);
usbhost_putle16(ctrlreq->len, USB_SIZEOF_DEVDESC);
ret = usbhost_ctrlxfer(devclass, ctrlreq, buffer);
ret = DRVR_CTRLIN(devclass->drvr, ctrlreq, buffer);
if (ret != OK)
{
udbg("ERROR: Failed to get device descriptor, length=%d: %d\n",
@@ -469,7 +454,7 @@ int usbhost_enumerate(FAR struct usbhost_class_s *devclass)
usbhost_putle16(ctrlreq->index, 0);
usbhost_putle16(ctrlreq->len, USB_SIZEOF_CFGDESC);
ret = usbhost_ctrlxfer(devclass, ctrlreq, buffer);
ret = DRVR_CTRLIN(devclass->drvr, ctrlreq, buffer);
if (ret != OK)
{
udbg("ERROR: Failed to get configuration descriptor, length=%d: %d\n",
@@ -492,7 +477,7 @@ int usbhost_enumerate(FAR struct usbhost_class_s *devclass)
usbhost_putle16(ctrlreq->index, 0);
usbhost_putle16(ctrlreq->len, cfglen);
ret = usbhost_ctrlxfer(devclass, ctrlreq, buffer);
ret = DRVR_CTRLIN(devclass->drvr, ctrlreq, buffer);
if (ret != OK)
{
udbg("ERROR: Failed to get configuration descriptor, length=%d: %d\n",
@@ -508,7 +493,7 @@ int usbhost_enumerate(FAR struct usbhost_class_s *devclass)
usbhost_putle16(ctrlreq->index, 0);
usbhost_putle16(ctrlreq->len, 0);
ret = usbhost_ctrlxfer(devclass, ctrlreq, NULL);
ret = DRVR_CTRLOUT(devclass->drvr, ctrlreq, NULL);
if (ret != OK)
{
udbg("ERROR: Failed to set configuration: %d\n", ret);
@@ -562,78 +547,3 @@ errout:
return ret;
}
/****************************************************************************
* Name: usbhost_ctrlxfer
*
* Description:
* Free transfer buffer memory.
*
* Input Parameters:
* devclass - A reference to the class instance.
* ctrlreq - Describes the control request transfer
* buffer - Data accompanying the control transfer
*
* Returned Values:
* On sucess, zero (OK) is returned. On failure, an negated errno value
* is returned to indicate the nature of the failure.
*
****************************************************************************/
int usbhost_ctrlxfer(FAR struct usbhost_class_s *devclass,
FAR struct usb_ctrlreq_s *ctrlreq,
FAR uint8_t *buffer)
{
struct usbhost_transfer_s xfer;
struct timespec timeout;
uint16_t len;
int ret;
len = usbhost_getle16(ctrlreq->len);
xfer.buffer = buffer;
xfer.buflen = len;
xfer.len = len;
xfer.status = -EIO;
xfer.devclass = devclass;
xfer.ep = devclass->ep0;
xfer.callback = usbhost_callback;
sem_init(&xfer.done, 0, 0);
#ifdef CONFIG_USBHOST_HUB
if (ROOTHUB(devclass))
{
ret = DRVR_RHCTRL(devclass->drvr, &xfer, ctrlreq);
}
else
#endif
{
if ((ctrlreq->type & USB_REQ_DIR_IN) != 0)
{
ret = DRVR_CTRLIN(devclass->drvr, &xfer, ctrlreq);
}
else
{
ret = DRVR_CTRLOUT(devclass->drvr, &xfer, ctrlreq);
}
}
if (ret != OK)
{
goto out;
}
timeout.tv_sec = 5;
timeout.tv_nsec = 1000*1000;
ret = sem_timedwait(&xfer.done, &timeout);
if (ret == OK)
{
ret = xfer.status;
}
out:
sem_destroy(&xfer.done);
return ret;
}
File diff suppressed because it is too large Load Diff
+17 -81
View File
@@ -52,9 +52,6 @@
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <semaphore.h>
#include <nuttx/wqueue.h>
/************************************************************************************
* Pre-processor Definitions
@@ -451,7 +448,7 @@
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method.
* xfr - Describes the request to be sent. This request must lie in memory
* req - Describes the request to be sent. This request must lie in memory
* created by DRVR_ALLOC.
* buffer - A buffer used for sending the request and for returning any
* responses. This buffer must be large enough to hold the length value
@@ -469,8 +466,8 @@
*
************************************************************************************/
#define DRVR_CTRLIN(drvr,xfer,cmd) ((drvr)->ctrlin(drvr,xfer,cmd))
#define DRVR_CTRLOUT(drvr,xfer,cmd) ((drvr)->ctrlout(drvr,xfer,cmd))
#define DRVR_CTRLIN(drvr,req,buffer) ((drvr)->ctrlin(drvr,req,buffer))
#define DRVR_CTRLOUT(drvr,req,buffer) ((drvr)->ctrlout(drvr,req,buffer))
/************************************************************************************
* Name: DRVR_TRANSFER
@@ -535,7 +532,7 @@
#define DRVR_DISCONNECT(drvr) ((drvr)->disconnect(drvr))
/************************************************************************************
* Name: DRVR_RHCTRL and DRVR_RHSTATUS
* Name: DRVR_RHSTATUS
*
* Description:
* Called by hub class to control root hub.
@@ -558,7 +555,6 @@
************************************************************************************/
#ifdef CONFIG_USBHOST_HUB
# define DRVR_RHCTRL(drvr,xfer,cmd) ((drvr)->rhctrl(drvr,xfer,cmd))
# define DRVR_RHSTATUS(drvr,xfer) ((drvr)->rhstatus(drvr,xfer))
#endif
@@ -630,34 +626,14 @@ typedef FAR void *usbhost_ep_t;
struct usbhost_class_s
{
#ifdef CONFIG_USBHOST_HUB
/* Common host driver */
FAR struct usbhost_driver_s *drvr;
/* Parent class */
FAR struct usbhost_class_s *parent;
/* Control endpoint, ep0 */
usbhost_ep_t ep0;
/* Transaction translator hub */
FAR struct usb_hubtt_s *tt;
/* Class specific private data */
FAR void *priv;
/* USB device address & speed */
uint8_t addr;
uint8_t speed;
/* Transaction translator port */
uint8_t ttport;
FAR struct usbhost_driver_s *drvr; /* Common host driver */
FAR struct usbhost_class_s *parent; /* Parent class */
usbhost_ep_t ep0; /* Control endpoint, ep0 */
FAR struct usb_hubtt_s *tt; /* Transaction translator hub */
FAR void *priv; /* Class specific private data */
uint8_t addr; /* Device function address */
uint8_t speed; /* Device speed */
uint8_t rhport; /* Root hub port index */
#endif
/* Provides the configuration descriptor to the class. The configuration
@@ -698,34 +674,18 @@ struct usbhost_devinfo_s
{
uint8_t speed:2; /* Device speed: 0=low, 1=full, 2=high */
};
/* Generic transfer structure */
struct usbhost_transfer_s
{
FAR uint8_t *buffer;
size_t buflen;
size_t len;
int status;
/* Semaphore of synchronized transfers */
sem_t done;
/* Device class */
FAR struct usbhost_class_s *devclass;
/* Opaque endpoint pointer; can be xHCI specific */
usbhost_ep_t ep;
/* Workqueue for callback */
struct work_s work;
/* Transfer complete callback */
void (*callback)(FAR struct usbhost_transfer_s *);
};
/* struct usbhost_connection_s provides as interface between platform-specific
@@ -826,11 +786,11 @@ struct usbhost_driver_s
*/
int (*ctrlin)(FAR struct usbhost_driver_s *drvr,
FAR struct usbhost_transfer_s *xfer,
FAR const struct usb_ctrlreq_s *cmd);
FAR const struct usb_ctrlreq_s *req,
FAR uint8_t *buffer);
int (*ctrlout)(FAR struct usbhost_driver_s *drvr,
FAR struct usbhost_transfer_s *xfer,
FAR const struct usb_ctrlreq_s *cmd);
FAR const struct usb_ctrlreq_s *req,
FAR const uint8_t *buffer);
/* Process a request to handle a transfer descriptor. This method will
* enqueue the transfer request and wait for it to complete. Only one transfer may
@@ -855,9 +815,6 @@ struct usbhost_driver_s
#ifdef CONFIG_USBHOST_HUB
/* Called by hub class to control root hub. */
int (*rhctrl)(FAR struct usbhost_driver_s *drvr,
FAR struct usbhost_transfer_s *xfer,
FAR const struct usb_ctrlreq_s *cmd);
int (*rhstatus)(FAR struct usbhost_driver_s *drvr,
FAR struct usbhost_transfer_s *xfer);
#endif
@@ -1058,27 +1015,6 @@ int usbhost_wlaninit(void);
int usbhost_enumerate(FAR struct usbhost_class_s *devclass);
/****************************************************************************
* Name: usbhost_ctrlxfer
*
* Description:
* Free transfer buffer memory.
*
* Input Parameters:
* devclass - A reference to the class instance.
* ctrlreq - Describes the control request transfer
* buffer - Data accompanying the control transfer
*
* Returned Values:
* On success, zero (OK) is returned. On failure, an negated errno value
* is returned to indicate the nature of the failure.
*
****************************************************************************/
int usbhost_ctrlxfer(FAR struct usbhost_class_s *devclass,
FAR struct usb_ctrlreq_s *ctrlreq,
FAR uint8_t *buffer);
#ifdef CONFIG_USBHOST_HUB
/*******************************************************************************
* Name: usbhost_rh_connect