USB host: Remove getdevinfo() method. Rename hub structure to hubport structure. Get port and function address from hub port structure vs. parameters and other structures.
This commit is contained in:
parent
2ea7a83bf5
commit
d62aa8c158
@ -68,13 +68,13 @@ static inline uint16_t usbhost_getle16(const uint8_t *val);
|
||||
static void usbhost_putle16(uint8_t *dest, uint16_t val);
|
||||
|
||||
static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc,
|
||||
FAR struct usbhost_id_s *id);
|
||||
FAR struct usbhost_id_s *id);
|
||||
static inline int usbhost_configdesc(const uint8_t *configdesc, int desclen,
|
||||
FAR struct usbhost_id_s *id);
|
||||
static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
const uint8_t *configdesc, int desclen,
|
||||
struct usbhost_id_s *id,
|
||||
FAR struct usbhost_class_s **devclass);
|
||||
FAR struct usbhost_id_s *id);
|
||||
static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const uint8_t *configdesc, int desclen,
|
||||
FAR struct usbhost_id_s *id,
|
||||
FAR struct usbhost_class_s **devclass);
|
||||
|
||||
/*******************************************************************************
|
||||
* Private Data
|
||||
@ -222,7 +222,7 @@ static inline int usbhost_configdesc(const uint8_t *configdesc, int cfglen,
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport,
|
||||
const uint8_t *configdesc, int desclen,
|
||||
struct usbhost_id_s *id,
|
||||
FAR struct usbhost_class_s **usbclass)
|
||||
@ -242,7 +242,7 @@ static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
*/
|
||||
|
||||
ret = -ENOMEM;
|
||||
devclass = CLASS_CREATE(reg, hub, port, id);
|
||||
devclass = CLASS_CREATE(reg, hport, id);
|
||||
uvdbg("CLASS_CREATE: %p\n", devclass);
|
||||
if (devclass != NULL)
|
||||
{
|
||||
@ -287,11 +287,10 @@ static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
* charge of the sequence of operations.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - The hub that manages the new class.
|
||||
* port - The hub port index
|
||||
* hport - The hub port that manages the new class.
|
||||
* devclass - If the class driver for the device is successful located
|
||||
* and bound to the hub, the allocated class instance is returned into
|
||||
* this caller-provided memory location.
|
||||
* and bound to the hub port, the allocated class instance is returned
|
||||
* into this caller-provided memory location.
|
||||
*
|
||||
* Returned Values:
|
||||
* On success, zero (OK) is returned. On a failure, a negated errno value is
|
||||
@ -304,11 +303,10 @@ static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
int usbhost_enumerate(FAR struct usbhost_hubport_s *hport,
|
||||
FAR struct usbhost_class_s **devclass)
|
||||
{
|
||||
FAR struct usb_ctrlreq_s *ctrlreq = NULL;
|
||||
struct usbhost_devinfo_s devinfo;
|
||||
struct usbhost_id_s id;
|
||||
size_t maxlen;
|
||||
unsigned int cfglen;
|
||||
@ -317,35 +315,26 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
FAR uint8_t *buffer = NULL;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(hub != NULL && hub->drvr != NULL);
|
||||
DEBUGASSERT(hport != NULL && hport->drvr != NULL);
|
||||
|
||||
/* Allocate descriptor buffers for use in this function. We will need two:
|
||||
* One for the request and one for the data buffer.
|
||||
*/
|
||||
|
||||
ret = DRVR_ALLOC(hub->drvr, (FAR uint8_t **)&ctrlreq, &maxlen);
|
||||
ret = DRVR_ALLOC(hport->drvr, (FAR uint8_t **)&ctrlreq, &maxlen);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("DRVR_ALLOC failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = DRVR_ALLOC(hub->drvr, &buffer, &maxlen);
|
||||
ret = DRVR_ALLOC(hport->drvr, &buffer, &maxlen);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("DRVR_ALLOC failed: %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Get information about the connected device */
|
||||
|
||||
ret = DRVR_GETDEVINFO(hub->drvr, &devinfo);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("DRVR_GETDEVINFO failed: %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Pick an appropriate packet size for this device
|
||||
*
|
||||
* USB 2.0, Paragraph 5.5.3 "Control Transfer Packet Size Constraints"
|
||||
@ -359,7 +348,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
* Data packets following a Setup..."
|
||||
*/
|
||||
|
||||
if (devinfo.speed == DEVINFO_SPEED_HIGH)
|
||||
if (hport->speed == USB_SPEED_HIGH)
|
||||
{
|
||||
/* For high-speed, we must use 64 bytes */
|
||||
|
||||
@ -376,7 +365,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
|
||||
/* Configure EP0 with the initial maximum packet size */
|
||||
|
||||
DRVR_EP0CONFIGURE(hub->drvr, hub->ep0, 0, maxpacketsize);
|
||||
DRVR_EP0CONFIGURE(hport->drvr, hport->ep0, 0, maxpacketsize);
|
||||
|
||||
/* Read first bytes of the device descriptor */
|
||||
|
||||
@ -386,7 +375,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, descsize);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq, buffer);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, buffer);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to get device descriptor, length=%d: %d\n",
|
||||
@ -401,17 +390,17 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
|
||||
/* And reconfigure EP0 with the correct maximum packet size */
|
||||
|
||||
DRVR_EP0CONFIGURE(hub->drvr, hub->ep0, 0, maxpacketsize);
|
||||
DRVR_EP0CONFIGURE(hport->drvr, hport->ep0, 0, maxpacketsize);
|
||||
|
||||
/* Set the USB device address */
|
||||
|
||||
ctrlreq->type = USB_REQ_DIR_OUT | USB_REQ_RECIPIENT_DEVICE;
|
||||
ctrlreq->req = USB_REQ_SETADDRESS;
|
||||
usbhost_putle16(ctrlreq->value, ((uint16_t)hub->funcaddr << 8));
|
||||
usbhost_putle16(ctrlreq->value, ((uint16_t)hport->funcaddr << 8));
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
ret = DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
ret = DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to set address: %d\n");
|
||||
@ -422,7 +411,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
|
||||
/* And reconfigure EP0 with the correct address */
|
||||
|
||||
DRVR_EP0CONFIGURE(hub->drvr, hub->ep0, hub->funcaddr, maxpacketsize);
|
||||
DRVR_EP0CONFIGURE(hport->drvr, hport->ep0, hport->funcaddr, maxpacketsize);
|
||||
|
||||
/* Now read the full device descriptor (if we have not already done so) */
|
||||
|
||||
@ -434,7 +423,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, USB_SIZEOF_DEVDESC);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq, buffer);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, buffer);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to get device descriptor, length=%d: %d\n",
|
||||
@ -462,7 +451,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, USB_SIZEOF_CFGDESC);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq, buffer);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, buffer);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to get configuration descriptor, length=%d: %d\n",
|
||||
@ -485,7 +474,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, cfglen);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq, buffer);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, buffer);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to get configuration descriptor, length=%d: %d\n",
|
||||
@ -501,7 +490,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
ret = DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
ret = DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to set configuration: %d\n", ret);
|
||||
@ -536,7 +525,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
* will begin configuring the device.
|
||||
*/
|
||||
|
||||
ret = usbhost_classbind(hub, port, buffer, cfglen, &id, devclass);
|
||||
ret = usbhost_classbind(hport, buffer, cfglen, &id, devclass);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: usbhost_classbind returned %d\n", ret);
|
||||
@ -545,12 +534,12 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
errout:
|
||||
if (buffer != NULL)
|
||||
{
|
||||
DRVR_FREE(hub->drvr, buffer);
|
||||
DRVR_FREE(hport->drvr, buffer);
|
||||
}
|
||||
|
||||
if (ctrlreq)
|
||||
{
|
||||
DRVR_FREE(hub->drvr, (FAR uint8_t *)ctrlreq);
|
||||
DRVR_FREE(hport->drvr, (FAR uint8_t *)ctrlreq);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -196,10 +196,6 @@ struct usbhost_state_s
|
||||
|
||||
struct usbhost_class_s usbclass;
|
||||
|
||||
/* This is an instance of the USB host driver bound to this class instance */
|
||||
|
||||
struct usbhost_hub_s *hub; /* The hub that manages the endpoint */
|
||||
|
||||
/* The remainder of the fields are provide o the keyboard class driver */
|
||||
|
||||
char devchar; /* Character identifying the /dev/kbd[n] device */
|
||||
@ -322,7 +318,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv);
|
||||
/* struct usbhost_registry_s methods */
|
||||
|
||||
static struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id);
|
||||
|
||||
/* struct usbhost_class_s methods */
|
||||
@ -758,11 +754,11 @@ static inline void usbhost_mkdevname(FAR struct usbhost_state_s *priv, char *dev
|
||||
static void usbhost_destroy(FAR void *arg)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)arg;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
char devname[DEV_NAMELEN];
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->hub != NULL);
|
||||
hub = priv->hub;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
uvdbg("crefs: %d\n", priv->crefs);
|
||||
|
||||
@ -780,12 +776,12 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
if (priv->epin)
|
||||
{
|
||||
DRVR_EPFREE(hub->drvr, priv->epin);
|
||||
DRVR_EPFREE(hport->drvr, priv->epin);
|
||||
}
|
||||
|
||||
if (priv->epout)
|
||||
{
|
||||
DRVR_EPFREE(hub->drvr, priv->epout);
|
||||
DRVR_EPFREE(hport->drvr, priv->epout);
|
||||
}
|
||||
|
||||
/* Free any transfer buffers */
|
||||
@ -799,7 +795,7 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
/* Disconnect the USB host device */
|
||||
|
||||
DRVR_DISCONNECT(hub->drvr);
|
||||
DRVR_DISCONNECT(hport->drvr);
|
||||
|
||||
/* And free the class instance. Hmmm.. this may execute on the worker
|
||||
* thread and the work structure is part of what is getting freed. That
|
||||
@ -1003,18 +999,18 @@ static inline void usbhost_encodescancode(FAR struct usbhost_state_s *priv,
|
||||
static int usbhost_kbdpoll(int argc, char *argv[])
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usb_ctrlreq_s *ctrlreq;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_ctrlreq_s *ctrlreq;
|
||||
#ifndef CONFIG_HIDKBD_NODEBOUNCE
|
||||
uint8_t lastkey[6] = {0, 0, 0, 0, 0, 0};
|
||||
uint8_t lastkey[6] = {0, 0, 0, 0, 0, 0};
|
||||
#endif
|
||||
#if defined(CONFIG_DEBUG_USB) && defined(CONFIG_DEBUG_VERBOSE)
|
||||
unsigned int npolls = 0;
|
||||
unsigned int npolls = 0;
|
||||
#endif
|
||||
unsigned int nerrors = 0;
|
||||
bool empty = true;
|
||||
bool newstate;
|
||||
int ret;
|
||||
unsigned int nerrors = 0;
|
||||
bool empty = true;
|
||||
bool newstate;
|
||||
int ret;
|
||||
|
||||
uvdbg("Started\n");
|
||||
|
||||
@ -1028,8 +1024,8 @@ static int usbhost_kbdpoll(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
priv = g_priv;
|
||||
DEBUGASSERT(priv != NULL && priv->hub);
|
||||
hub = priv->hub;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
priv->polling = true;
|
||||
priv->crefs++;
|
||||
@ -1069,7 +1065,7 @@ static int usbhost_kbdpoll(int argc, char *argv[])
|
||||
|
||||
/* Send HID report request */
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq, priv->tbuffer);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, priv->tbuffer);
|
||||
usbhost_givesem(&priv->exclsem);
|
||||
|
||||
/* Check for errors -- Bail if an excessive number of errors
|
||||
@ -1292,7 +1288,7 @@ static int usbhost_kbdpoll(int argc, char *argv[])
|
||||
static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
FAR const uint8_t *configdesc, int desclen)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_cfgdesc_s *cfgdesc;
|
||||
FAR struct usb_desc_s *desc;
|
||||
FAR struct usbhost_epdesc_s epindesc;
|
||||
@ -1302,9 +1298,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
bool done = false;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->hub != NULL && configdesc != NULL &&
|
||||
desclen >= sizeof(struct usb_cfgdesc_s));
|
||||
hub = priv->hub;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL &&
|
||||
configdesc != NULL && desclen >= sizeof(struct usb_cfgdesc_s));
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Keep the compiler from complaining about uninitialized variables */
|
||||
|
||||
@ -1414,9 +1410,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* Save the interrupt OUT endpoint information */
|
||||
|
||||
epoutdesc.hport = hport;
|
||||
epoutdesc.addr = epdesc->addr & USB_EP_ADDR_NUMBER_MASK;
|
||||
epoutdesc.in = false;
|
||||
epoutdesc.funcaddr = hub->funcaddr;
|
||||
epoutdesc.xfrtype = USB_EP_ATTR_XFER_INT;
|
||||
epoutdesc.interval = epdesc->interval;
|
||||
epoutdesc.mxpacketsize = usbhost_getle16(epdesc->mxpacketsize);
|
||||
@ -1442,9 +1438,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* Save the interrupt IN endpoint information */
|
||||
|
||||
epindesc.hport = hport;
|
||||
epindesc.addr = epdesc->addr & USB_EP_ADDR_NUMBER_MASK;
|
||||
epindesc.in = 1;
|
||||
epindesc.funcaddr = hub->funcaddr;
|
||||
epindesc.xfrtype = USB_EP_ATTR_XFER_INT;
|
||||
epindesc.interval = epdesc->interval;
|
||||
epindesc.mxpacketsize = usbhost_getle16(epdesc->mxpacketsize);
|
||||
@ -1491,7 +1487,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
* IN endpoint.
|
||||
*/
|
||||
|
||||
ret = DRVR_EPALLOC(hub->drvr, &epindesc, &priv->epin);
|
||||
ret = DRVR_EPALLOC(hport->drvr, &epindesc, &priv->epin);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to allocate interrupt IN endpoint\n");
|
||||
@ -1505,11 +1501,11 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
if ((found & USBHOST_EPOUTFOUND) != 0)
|
||||
{
|
||||
ret = DRVR_EPALLOC(hub->drvr, &epoutdesc, &priv->epout);
|
||||
ret = DRVR_EPALLOC(hport->drvr, &epoutdesc, &priv->epout);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to allocate interrupt OUT endpoint\n");
|
||||
(void)DRVR_EPFREE(hub->drvr, priv->epin);
|
||||
(void)DRVR_EPFREE(hport->drvr, priv->epin);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -1717,12 +1713,13 @@ static void usbhost_putle32(uint8_t *dest, uint32_t val)
|
||||
|
||||
static inline int usbhost_tdalloc(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->hub != NULL && priv->tbuffer == NULL);
|
||||
hub = priv->hub;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL &&
|
||||
priv->tbuffer == NULL);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
return DRVR_ALLOC(hub->drvr, &priv->tbuffer, &priv->tbuflen);
|
||||
return DRVR_ALLOC(hport->drvr, &priv->tbuffer, &priv->tbuflen);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -1742,16 +1739,16 @@ static inline int usbhost_tdalloc(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
int result = OK;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
|
||||
if (priv->tbuffer)
|
||||
{
|
||||
DEBUGASSERT(priv->hub);
|
||||
hub = priv->hub;
|
||||
result = DRVR_FREE(hub->drvr, priv->tbuffer);
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
result = DRVR_FREE(hport->drvr, priv->tbuffer);
|
||||
priv->tbuffer = NULL;
|
||||
priv->tbuflen = 0;
|
||||
}
|
||||
@ -1775,8 +1772,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
|
||||
* USB ports and multiple USB devices simultaneously connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - The hub that manages the new class instance.
|
||||
* port - The hub port index
|
||||
* hport - The hub port that manages the new class instance.
|
||||
* id - In the case where the device supports multiple base classes,
|
||||
* subclasses, or protocols, this specifies which to configure for.
|
||||
*
|
||||
@ -1784,13 +1780,13 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
|
||||
* On success, this function will return a non-NULL instance of struct
|
||||
* usbhost_class_s that can be used by the USB host driver to communicate
|
||||
* with the USB host class. NULL is returned on failure; this function
|
||||
* will fail only if the hub input parameter is NULL or if there are
|
||||
* will fail only if the hport input parameter is NULL or if there are
|
||||
* insufficient resources to create another USB host class instance.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
@ -1810,8 +1806,7 @@ static FAR struct usbhost_class_s *
|
||||
{
|
||||
/* Initialize class method function pointers */
|
||||
|
||||
priv->usbclass.hub = hub;
|
||||
priv->usbclass.port = port;
|
||||
priv->usbclass.hport = hport;
|
||||
priv->usbclass.connect = usbhost_connect;
|
||||
priv->usbclass.disconnected = usbhost_disconnected;
|
||||
|
||||
@ -1826,10 +1821,6 @@ static FAR struct usbhost_class_s *
|
||||
sem_init(&priv->exclsem, 0, 1);
|
||||
sem_init(&priv->waitsem, 0, 0);
|
||||
|
||||
/* Bind the hub to the storage class instance */
|
||||
|
||||
priv->hub = hub;
|
||||
|
||||
/* Return the instance of the USB keyboard class driver */
|
||||
|
||||
return &priv->usbclass;
|
||||
|
@ -370,7 +370,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv);
|
||||
/* struct usbhost_registry_s methods */
|
||||
|
||||
static struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id);
|
||||
|
||||
/* struct usbhost_class_s methods */
|
||||
@ -615,13 +615,13 @@ static inline void usbhost_mkdevname(FAR struct usbhost_state_s *priv,
|
||||
static void usbhost_destroy(FAR void *arg)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)arg;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
char devname[DEV_NAMELEN];
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hub != NULL);
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL);
|
||||
uvdbg("crefs: %d\n", priv->crefs);
|
||||
|
||||
hub = priv->usbclass.hub;
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Unregister the driver */
|
||||
|
||||
@ -637,7 +637,7 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
if (priv->epin)
|
||||
{
|
||||
DRVR_EPFREE(hub->drvr, priv->epin);
|
||||
DRVR_EPFREE(hport->drvr, priv->epin);
|
||||
}
|
||||
|
||||
/* Free any transfer buffers */
|
||||
@ -651,7 +651,7 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
/* Disconnect the USB host device */
|
||||
|
||||
DRVR_DISCONNECT(hub->drvr);
|
||||
DRVR_DISCONNECT(hport->drvr);
|
||||
|
||||
/* And free the class instance. Hmmm.. this may execute on the worker
|
||||
* thread and the work structure is part of what is getting freed. That
|
||||
@ -1038,7 +1038,7 @@ static bool usbhost_threshold(FAR struct usbhost_state_s *priv)
|
||||
static int usbhost_mouse_poll(int argc, char *argv[])
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usbhid_mousereport_s *rpt;
|
||||
#ifndef CONFIG_HIDMOUSE_TSCIF
|
||||
uint8_t buttons;
|
||||
@ -1061,8 +1061,8 @@ static int usbhost_mouse_poll(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
priv = g_priv;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hub != NULL);
|
||||
hub = priv->usbclass.hub;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
priv->polling = true;
|
||||
priv->crefs++;
|
||||
@ -1079,7 +1079,7 @@ static int usbhost_mouse_poll(int argc, char *argv[])
|
||||
* sends data.
|
||||
*/
|
||||
|
||||
ret = DRVR_TRANSFER(hub->drvr, priv->epin,
|
||||
ret = DRVR_TRANSFER(hport->drvr, priv->epin,
|
||||
priv->tbuffer, priv->tbuflen);
|
||||
|
||||
/* Check for errors -- Bail if an excessive number of errors
|
||||
@ -1417,7 +1417,7 @@ errout:
|
||||
static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
FAR const uint8_t *configdesc, int desclen)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_cfgdesc_s *cfgdesc;
|
||||
FAR struct usb_desc_s *desc;
|
||||
FAR struct usbhost_epdesc_s epindesc;
|
||||
@ -1426,9 +1426,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
bool done = false;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hub != NULL &&
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL &&
|
||||
configdesc != NULL && desclen >= sizeof(struct usb_cfgdesc_s));
|
||||
hub = priv->usbclass.hub;
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Keep the compiler from complaining about uninitialized variables */
|
||||
|
||||
@ -1532,9 +1532,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* Save the interrupt IN endpoint information */
|
||||
|
||||
epindesc.hport = hport;
|
||||
epindesc.addr = epdesc->addr & USB_EP_ADDR_NUMBER_MASK;
|
||||
epindesc.in = true;
|
||||
epindesc.funcaddr = hub->funcaddr;
|
||||
epindesc.xfrtype = USB_EP_ATTR_XFER_INT;
|
||||
epindesc.interval = epdesc->interval;
|
||||
epindesc.mxpacketsize = usbhost_getle16(epdesc->mxpacketsize);
|
||||
@ -1580,7 +1580,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* We are good... Allocate the interrupt IN endpoint. */
|
||||
|
||||
ret = DRVR_EPALLOC(hub->drvr, &epindesc, &priv->epin);
|
||||
ret = DRVR_EPALLOC(hport->drvr, &epindesc, &priv->epin);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to allocate interrupt IN endpoint\n");
|
||||
@ -1790,12 +1790,13 @@ static void usbhost_putle32(uint8_t *dest, uint32_t val)
|
||||
|
||||
static inline int usbhost_tdalloc(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hub != NULL && priv->tbuffer == NULL);
|
||||
hub = priv->usbclass.hub;
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL &&
|
||||
priv->tbuffer == NULL);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
return DRVR_ALLOC(hub->drvr, &priv->tbuffer, &priv->tbuflen);
|
||||
return DRVR_ALLOC(hport->drvr, &priv->tbuffer, &priv->tbuflen);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -1815,15 +1816,15 @@ static inline int usbhost_tdalloc(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
int result = OK;
|
||||
DEBUGASSERT(priv);
|
||||
|
||||
if (priv->tbuffer)
|
||||
{
|
||||
DEBUGASSERT(priv->usbclass.hub);
|
||||
hub = priv->usbclass.hub;
|
||||
result = DRVR_FREE(hub->drvr, priv->tbuffer);
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
result = DRVR_FREE(hport->drvr, priv->tbuffer);
|
||||
priv->tbuffer = NULL;
|
||||
priv->tbuflen = 0;
|
||||
}
|
||||
@ -1847,8 +1848,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
|
||||
* USB ports and multiple USB devices simultaneously connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - The hub that manages the new class instance.
|
||||
* port - The hub port index
|
||||
* hport - The hub port that manages the new class instance.
|
||||
* id - In the case where the device supports multiple base classes,
|
||||
* subclasses, or protocols, this specifies which to configure for.
|
||||
*
|
||||
@ -1856,13 +1856,13 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
|
||||
* On success, this function will return a non-NULL instance of struct
|
||||
* usbhost_class_s that can be used by the USB host driver to communicate
|
||||
* with the USB host class. NULL is returned on failure; this function
|
||||
* will fail only if the hub input parameter is NULL or if there are
|
||||
* will fail only if the hport input parameter is NULL or if there are
|
||||
* insufficient resources to create another USB host class instance.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
@ -1882,8 +1882,7 @@ static FAR struct usbhost_class_s *
|
||||
{
|
||||
/* Initialize class method function pointers */
|
||||
|
||||
priv->usbclass.hub = hub;
|
||||
priv->usbclass.port = port;
|
||||
priv->usbclass.hport = hport;
|
||||
priv->usbclass.connect = usbhost_connect;
|
||||
priv->usbclass.disconnected = usbhost_disconnected;
|
||||
|
||||
|
@ -88,6 +88,7 @@ struct usbhost_hubpriv_s
|
||||
{
|
||||
FAR struct usb_ctrlreq_s *ctrlreq; /* Allocated control request */
|
||||
FAR uint8_t *buffer; /* Allocated buffer */
|
||||
|
||||
uint8_t ifno; /* Interface number */
|
||||
uint8_t nports; /* Number of ports */
|
||||
uint8_t lpsm; /* Logical power switching mode */
|
||||
@ -99,9 +100,8 @@ struct usbhost_hubpriv_s
|
||||
|
||||
uint16_t pwrondelay; /* Power on wait time in ms */
|
||||
int16_t crefs; /* Reference count on the driver instance */
|
||||
sem_t exclsem; /* Used to maintain mutual exclusive access */
|
||||
|
||||
struct usb_hubtt_s tt; /* Transaction translator */
|
||||
sem_t exclsem; /* Used to maintain mutual exclusive access */
|
||||
struct work_s work; /* Used for deferred callback work */
|
||||
usbhost_ep_t intin; /* Interrupt IN endpoint */
|
||||
|
||||
@ -127,11 +127,11 @@ struct usbhost_hubclass_s
|
||||
|
||||
static inline uint8_t usbhost_allocaddr(void);
|
||||
static inline void usbhost_freeaddr(uint8_t addr);
|
||||
static inline FAR struct usbhost_hub_s *usbhost_allochub(
|
||||
static inline FAR struct usbhost_hubport_s *usbhost_allochub(
|
||||
FAR struct usbhost_driver_s *drvr,
|
||||
FAR struct usbhost_class_s *hubclass, uint8_t speed,
|
||||
uint8_t port);
|
||||
static inline void usbhost_freehub(FAR struct usbhost_hub_s *hub);
|
||||
static inline void usbhost_freehub(FAR struct usbhost_hubport_s *hport);
|
||||
static inline void usbhost_freeclass(FAR struct usbhost_class_s *devclass);
|
||||
|
||||
/* Worker thread actions */
|
||||
@ -156,7 +156,7 @@ static void usbhost_callback(FAR void *arg, int result);
|
||||
/* struct usbhost_registry_s methods */
|
||||
|
||||
static FAR struct usbhost_class_s *usbhost_create(
|
||||
FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id);
|
||||
|
||||
/* struct usbhost_class_s methods */
|
||||
@ -260,28 +260,24 @@ static inline void usbhost_freeaddr(uint8_t addr)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR struct usbhost_hub_s *
|
||||
static inline FAR struct usbhost_hubport_s *
|
||||
usbhost_allochub(FAR struct usbhost_driver_s *drvr,
|
||||
FAR struct usbhost_class_s *hubclass,
|
||||
uint8_t speed, uint8_t port)
|
||||
{
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *child;
|
||||
FAR struct usbhost_hub_s *parent;
|
||||
FAR struct usbhost_hubport_s *child;
|
||||
FAR struct usbhost_hubport_s *parent;
|
||||
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
priv = &((FAR struct usbhost_hubclass_s *)hubclass)->hubpriv;
|
||||
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
parent = hubclass->hub;
|
||||
DEBUGASSERT(hubclass != NULL && hubclass->hport != NULL);
|
||||
parent = hubclass->hport;
|
||||
|
||||
/* We are not executing from an interrupt handler so we can just call
|
||||
* kmm_malloc() to get memory for the class instance.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(!up_interrupt_context());
|
||||
child = (FAR struct usbhost_hub_s *)
|
||||
kmm_malloc(sizeof(struct usbhost_hub_s));
|
||||
child = (FAR struct usbhost_hubport_s *)
|
||||
kmm_malloc(sizeof(struct usbhost_hubport_s));
|
||||
|
||||
uvdbg("Allocated: %p\n", child);
|
||||
|
||||
@ -292,21 +288,10 @@ static inline FAR struct usbhost_hub_s *
|
||||
|
||||
child->drvr = drvr;
|
||||
child->parent = parent;
|
||||
child->tt = NULL;
|
||||
child->funcaddr = usbhost_allocaddr();
|
||||
child->speed = speed;
|
||||
|
||||
if (parent->tt != NULL)
|
||||
{
|
||||
child->tt = parent->tt;
|
||||
}
|
||||
else if ((child->speed != USB_SPEED_HIGH) &&
|
||||
(parent->speed == USB_SPEED_HIGH))
|
||||
{
|
||||
child->tt = &priv->tt;
|
||||
}
|
||||
|
||||
epdesc.hub = child;
|
||||
epdesc.hport = child;
|
||||
epdesc.addr = 0;
|
||||
epdesc.in = 0;
|
||||
epdesc.xfrtype = USB_EP_ATTR_XFER_CONTROL;
|
||||
@ -332,29 +317,29 @@ static inline FAR struct usbhost_hub_s *
|
||||
* Free a hub instance previously allocated by usbhost_allochub().
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - A reference to the hub instance to be freed.
|
||||
* hport - A reference to the hub port instance to be freed.
|
||||
*
|
||||
* Returned Values:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void usbhost_freehub(FAR struct usbhost_hub_s *hub)
|
||||
static inline void usbhost_freehub(FAR struct usbhost_hubport_s *hport)
|
||||
{
|
||||
if (hub && !ROOTHUB(hub))
|
||||
if (hport && !ROOTHUB(hport))
|
||||
{
|
||||
if (hub->ep0 != NULL)
|
||||
if (hport->ep0 != NULL)
|
||||
{
|
||||
DRVR_EPFREE(hub->drvr, hub->ep0);
|
||||
hub->ep0 = NULL;
|
||||
DRVR_EPFREE(hport->drvr, hport->ep0);
|
||||
hport->ep0 = NULL;
|
||||
}
|
||||
|
||||
usbhost_freeaddr(hub->funcaddr);
|
||||
usbhost_freeaddr(hport->funcaddr);
|
||||
|
||||
/* Free the hub instance */
|
||||
/* Free the hport instance */
|
||||
|
||||
uvdbg("Freeing: %p\n", hub);
|
||||
kmm_free(hub);
|
||||
uvdbg("Freeing: %p\n", hport);
|
||||
kmm_free(hport);
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,7 +363,7 @@ static inline void usbhost_freeclass(FAR struct usbhost_class_s *devclass)
|
||||
|
||||
/* Free the bound hub */
|
||||
|
||||
usbhost_freehub(devclass->hub);
|
||||
usbhost_freehub(devclass->hport);
|
||||
|
||||
/* Free the class instance */
|
||||
|
||||
@ -406,7 +391,7 @@ static void usbhost_destroy(FAR void *arg)
|
||||
{
|
||||
FAR struct usbhost_class_s *hubclass = (FAR struct usbhost_class_s *)arg;
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
@ -416,9 +401,9 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
if (priv->intin)
|
||||
{
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DRVR_EPFREE(hub->drvr, priv->intin);
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
DRVR_EPFREE(hport->drvr, priv->intin);
|
||||
}
|
||||
|
||||
/* Destroy the semaphores */
|
||||
@ -468,7 +453,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_class_s *hubclass,
|
||||
FAR const uint8_t *configdesc, int desclen)
|
||||
{
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_cfgdesc_s *cfgdesc;
|
||||
FAR struct usb_desc_s *desc;
|
||||
FAR struct usbhost_epdesc_s intindesc;
|
||||
@ -479,8 +464,8 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_class_s *hubclass,
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
priv = &((FAR struct usbhost_hubclass_s *)hubclass)->hubpriv;
|
||||
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
|
||||
DEBUGASSERT(configdesc != NULL && desclen >= sizeof(struct usb_cfgdesc_s));
|
||||
|
||||
@ -488,7 +473,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_class_s *hubclass,
|
||||
* compiler complaints)
|
||||
*/
|
||||
|
||||
intindesc.hub = hub;
|
||||
intindesc.hport = hport;
|
||||
intindesc.addr = 0;
|
||||
intindesc.in = true;
|
||||
intindesc.xfrtype = USB_EP_ATTR_XFER_INT;
|
||||
@ -621,11 +606,11 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_class_s *hubclass,
|
||||
|
||||
/* We are good... Allocate the interrupt IN endpoint */
|
||||
|
||||
ret = DRVR_EPALLOC(hub->drvr, &intindesc, &priv->intin);
|
||||
ret = DRVR_EPALLOC(hport->drvr, &intindesc, &priv->intin);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to allocate Interrupt IN endpoint: %d\n", ret);
|
||||
(void)DRVR_EPFREE(hub->drvr, priv->intin);
|
||||
(void)DRVR_EPFREE(hport->drvr, priv->intin);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -657,7 +642,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_class_s *hubclass,
|
||||
static inline int usbhost_hubdesc(FAR struct usbhost_class_s *hubclass)
|
||||
{
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_ctrlreq_s *ctrlreq;
|
||||
struct usb_hubdesc_s hubdesc;
|
||||
uint16_t hubchar;
|
||||
@ -666,8 +651,8 @@ static inline int usbhost_hubdesc(FAR struct usbhost_class_s *hubclass)
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
priv = &((FAR struct usbhost_hubclass_s *)hubclass)->hubpriv;
|
||||
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
|
||||
/* Get the hub descriptor */
|
||||
|
||||
@ -680,7 +665,7 @@ static inline int usbhost_hubdesc(FAR struct usbhost_class_s *hubclass)
|
||||
usbhost_putle16(ctrlreq->index, 0);
|
||||
usbhost_putle16(ctrlreq->len, USB_SIZEOF_HUBDESC);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq, (FAR uint8_t *)&hubdesc);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, (FAR uint8_t *)&hubdesc);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to read hub descriptor: %d\n", ret);
|
||||
@ -725,19 +710,20 @@ static inline int usbhost_hubdesc(FAR struct usbhost_class_s *hubclass)
|
||||
static inline int usbhost_hubpwr(FAR struct usbhost_class_s *hubclass, bool on)
|
||||
{
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_ctrlreq_s *ctrlreq;
|
||||
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
priv = &((FAR struct usbhost_hubclass_s *)hubclass)->hubpriv;
|
||||
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
|
||||
if (on || ROOTHUB(hub))
|
||||
if (on || ROOTHUB(hport))
|
||||
{
|
||||
uint16_t req;
|
||||
int port, ret;
|
||||
int port;
|
||||
int ret;
|
||||
|
||||
if (on)
|
||||
{
|
||||
@ -761,7 +747,7 @@ static inline int usbhost_hubpwr(FAR struct usbhost_class_s *hubclass, bool on)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
ret = DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
ret = DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to power %d port %d: %d\n", on, port, ret);
|
||||
@ -794,8 +780,8 @@ static inline int usbhost_hubpwr(FAR struct usbhost_class_s *hubclass, bool on)
|
||||
static void usbhost_hubevent(FAR void *arg)
|
||||
{
|
||||
FAR struct usbhost_class_s *hubclass;
|
||||
FAR struct usbhost_hub_s *newhub;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *newhub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usb_ctrlreq_s *ctrlreq;
|
||||
struct usb_portstatus_s portstatus;
|
||||
@ -814,8 +800,8 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
DEBUGASSERT(priv->ctrlreq);
|
||||
ctrlreq = priv->ctrlreq;
|
||||
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
|
||||
statusmap = priv->buffer[0];
|
||||
|
||||
@ -840,7 +826,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, USB_SIZEOF_PORTSTS);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq,
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq,
|
||||
(FAR uint8_t *)&portstatus);
|
||||
if (ret != OK)
|
||||
{
|
||||
@ -865,7 +851,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
ret = DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
ret = DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to clear port %d change mask %x: %d\n",
|
||||
@ -901,7 +887,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, USB_SIZEOF_PORTSTS);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq,
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq,
|
||||
(FAR uint8_t *)&portstatus);
|
||||
if (ret != OK)
|
||||
{
|
||||
@ -934,7 +920,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
(void)DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
(void)DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
}
|
||||
|
||||
debouncetime += 25;
|
||||
@ -957,7 +943,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
ret = DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
ret = DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: ailed to reset port %d: %d\n", port, ret);
|
||||
@ -972,7 +958,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, USB_SIZEOF_PORTSTS);
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, ctrlreq,
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq,
|
||||
(FAR uint8_t *)&portstatus);
|
||||
if (ret != OK)
|
||||
{
|
||||
@ -999,7 +985,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
usbhost_putle16(ctrlreq->index, port);
|
||||
usbhost_putle16(ctrlreq->len, 0);
|
||||
|
||||
(void)DRVR_CTRLOUT(hub->drvr, hub->ep0, ctrlreq, NULL);
|
||||
(void)DRVR_CTRLOUT(hport->drvr, hport->ep0, ctrlreq, NULL);
|
||||
}
|
||||
|
||||
if (status & USBHUB_PORT_STAT_HIGH_SPEED)
|
||||
@ -1017,19 +1003,18 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
|
||||
/* Allocate new hub class and enumerate */
|
||||
|
||||
newhub = usbhost_allochub(hub->drvr, hubclass, speed, port);
|
||||
newhub = usbhost_allochub(hport->drvr, hubclass, speed, port);
|
||||
if (newhub)
|
||||
{
|
||||
udbg("ERROR: Failed to allocated class\n");
|
||||
uvdbg("enumerate port %d speed %d\n", port, speed);
|
||||
|
||||
ret = usbhost_enumerate(newhub, port,
|
||||
&priv->childclass[port]);
|
||||
ret = usbhost_enumerate(newhub, &priv->childclass[port]);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to enumerate port %d: %d\n",
|
||||
port, ret);
|
||||
usbhost_freehub(hub);
|
||||
usbhost_freehub(hport);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1059,7 +1044,7 @@ static void usbhost_hubevent(FAR void *arg)
|
||||
|
||||
/* Get the number hub event */
|
||||
|
||||
ret = DRVR_ASYNCH(hub->drvr, priv->intin, (FAR uint8_t *)priv->ctrlreq,
|
||||
ret = DRVR_ASYNCH(hport->drvr, priv->intin, (FAR uint8_t *)priv->ctrlreq,
|
||||
sizeof(struct usb_ctrlreq_s), usbhost_callback,
|
||||
hubclass);
|
||||
if (ret != OK)
|
||||
@ -1157,8 +1142,7 @@ static void usbhost_callback(FAR void *arg, int result)
|
||||
* USB ports and multiple USB devices simultaneously connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - The hub that manages the new class instance.
|
||||
* port - The hub port index
|
||||
* hport - The hub port that manages the new class instance.
|
||||
* id - In the case where the device supports multiple base classes,
|
||||
* subclasses, or protocols, this specifies which to configure for.
|
||||
*
|
||||
@ -1166,13 +1150,13 @@ static void usbhost_callback(FAR void *arg, int result)
|
||||
* On success, this function will return a non-NULL instance of struct
|
||||
* usbhost_class_s that can be used by the USB host driver to communicate
|
||||
* with the USB host class. NULL is returned on failure; this function
|
||||
* will fail only if the hub input parameter is NULL or if there are
|
||||
* will fail only if the hport input parameter is NULL or if there are
|
||||
* insufficient resources to create another USB host class instance.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id)
|
||||
{
|
||||
FAR struct usbhost_hubclass_s *alloc;
|
||||
@ -1193,8 +1177,7 @@ static FAR struct usbhost_class_s *
|
||||
/* Initialize the public class structure */
|
||||
|
||||
hubclass = &alloc->hubclass;
|
||||
hubclass->hub = hub;
|
||||
hubclass->port = port;
|
||||
hubclass->hport = hport;
|
||||
hubclass->connect = usbhost_connect;
|
||||
hubclass->disconnected = usbhost_disconnected;
|
||||
|
||||
@ -1204,7 +1187,7 @@ static FAR struct usbhost_class_s *
|
||||
|
||||
/* Allocate memory for control requests */
|
||||
|
||||
ret = DRVR_ALLOC(hub->drvr, (FAR uint8_t **)&priv->ctrlreq, &maxlen);
|
||||
ret = DRVR_ALLOC(hport->drvr, (FAR uint8_t **)&priv->ctrlreq, &maxlen);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("DRVR_ALLOC failed: %d\n", ret);
|
||||
@ -1213,7 +1196,7 @@ static FAR struct usbhost_class_s *
|
||||
|
||||
/* Allocate buffer for status change (INT) endpoint */
|
||||
|
||||
ret = DRVR_IOALLOC(hub->drvr, &priv->buffer, 1);
|
||||
ret = DRVR_IOALLOC(hport->drvr, &priv->buffer, 1);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("DRVR_ALLOC failed: %d\n", ret);
|
||||
@ -1285,7 +1268,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *hubclass,
|
||||
FAR const uint8_t *configdesc, int desclen)
|
||||
{
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
@ -1320,10 +1303,10 @@ static int usbhost_connect(FAR struct usbhost_class_s *hubclass,
|
||||
|
||||
/* INT request to periodically check port status */
|
||||
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
|
||||
ret = DRVR_ASYNCH(hub->drvr, priv->intin, (FAR uint8_t *)&priv->ctrlreq,
|
||||
ret = DRVR_ASYNCH(hport->drvr, priv->intin, (FAR uint8_t *)&priv->ctrlreq,
|
||||
sizeof(struct usb_ctrlreq_s), usbhost_callback,
|
||||
hubclass);
|
||||
}
|
||||
@ -1356,7 +1339,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *hubclass,
|
||||
static int usbhost_disconnected(struct usbhost_class_s *hubclass)
|
||||
{
|
||||
FAR struct usbhost_hubpriv_s *priv;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
irqstate_t flags;
|
||||
|
||||
DEBUGASSERT(hubclass != NULL);
|
||||
@ -1378,14 +1361,15 @@ static int usbhost_disconnected(struct usbhost_class_s *hubclass)
|
||||
ullvdbg("crefs: %d\n", priv->crefs);
|
||||
if (priv->crefs == 1)
|
||||
{
|
||||
DEBUGASSERT(hubclass->hub);
|
||||
hub = hubclass->hub;
|
||||
DEBUGASSERT(hubclass->hport);
|
||||
hport = hubclass->hport;
|
||||
|
||||
/* Free buffer for status change (INT) endpoint */
|
||||
|
||||
DRVR_IOFREE(hub->drvr, priv->buffer);
|
||||
DRVR_IOFREE(hport->drvr, priv->buffer);
|
||||
|
||||
/* Power off (for root hub only) */
|
||||
|
||||
(void)usbhost_hubpwr(hubclass, false);
|
||||
|
||||
/* Destroy the class instance */
|
||||
|
@ -120,10 +120,6 @@ struct usbhost_state_s
|
||||
|
||||
struct usbhost_class_s usbclass;
|
||||
|
||||
/* This is an instance of the USB hub bound to this class instance */
|
||||
|
||||
struct usbhost_hub_s *hub;
|
||||
|
||||
/* The remainder of the fields are provide to the mass storage class */
|
||||
|
||||
char sdchar; /* Character identifying the /dev/sd[n] device */
|
||||
@ -228,7 +224,7 @@ static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *pri
|
||||
/* struct usbhost_registry_s methods */
|
||||
|
||||
static struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id);
|
||||
|
||||
/* struct usbhost_class_s methods */
|
||||
@ -678,7 +674,7 @@ usbhost_writecbw(size_t startsector, uint16_t blocksize,
|
||||
static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usb_ctrlreq_s *req = (FAR struct usb_ctrlreq_s *)priv->tbuffer;
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
DEBUGASSERT(priv && priv->tbuffer);
|
||||
int ret;
|
||||
|
||||
@ -694,10 +690,10 @@ static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv)
|
||||
req->req = USBMSC_REQ_GETMAXLUN;
|
||||
usbhost_putle16(req->len, 1);
|
||||
|
||||
DEBUGASSERT(priv->hub);
|
||||
hub = priv->hub;
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
ret = DRVR_CTRLIN(hub->drvr, hub->ep0, req, priv->tbuffer);
|
||||
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, req, priv->tbuffer);
|
||||
if (ret != OK)
|
||||
{
|
||||
/* Devices that do not support multiple LUNs may stall this command.
|
||||
@ -712,9 +708,13 @@ static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usbmsc_cbw_s *cbw;
|
||||
int result;
|
||||
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Initialize a CBW (re-using the allocated transfer buffer) */
|
||||
|
||||
cbw = usbhost_cbwalloc(priv);
|
||||
@ -727,13 +727,13 @@ static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv)
|
||||
/* Construct and send the CBW */
|
||||
|
||||
usbhost_testunitreadycbw(cbw);
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)cbw, USBMSC_CBW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the CSW */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, USBMSC_CSW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -746,9 +746,13 @@ static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usbmsc_cbw_s *cbw;
|
||||
int result;
|
||||
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Initialize a CBW (re-using the allocated transfer buffer) */
|
||||
|
||||
cbw = usbhost_cbwalloc(priv);
|
||||
@ -761,19 +765,19 @@ static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv)
|
||||
/* Construct and send the CBW */
|
||||
|
||||
usbhost_requestsensecbw(cbw);
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)cbw, USBMSC_CBW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the sense data response */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, SCSIRESP_FIXEDSENSEDATA_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the CSW */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, USBMSC_CSW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -787,10 +791,14 @@ static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usbmsc_cbw_s *cbw;
|
||||
FAR struct scsiresp_readcapacity10_s *resp;
|
||||
int result;
|
||||
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Initialize a CBW (re-using the allocated transfer buffer) */
|
||||
|
||||
cbw = usbhost_cbwalloc(priv);
|
||||
@ -803,13 +811,13 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv)
|
||||
/* Construct and send the CBW */
|
||||
|
||||
usbhost_readcapacitycbw(cbw);
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)cbw, USBMSC_CBW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the read capacity CBW IN response */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, SCSIRESP_READCAPACITY10_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -821,7 +829,7 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv)
|
||||
|
||||
/* Receive the CSW */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, USBMSC_CSW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -835,9 +843,13 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usbmsc_cbw_s *cbw;
|
||||
int result;
|
||||
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Initialize a CBW (re-using the allocated transfer buffer) */
|
||||
|
||||
cbw = usbhost_cbwalloc(priv);
|
||||
@ -850,13 +862,13 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv)
|
||||
/* Construct and send the CBW */
|
||||
|
||||
usbhost_inquirycbw(cbw);
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)cbw, USBMSC_CBW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the CBW IN response */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, SCSIRESP_INQUIRY_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -869,7 +881,7 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv)
|
||||
|
||||
/* Receive the CSW */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, USBMSC_CSW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -900,9 +912,12 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv)
|
||||
static void usbhost_destroy(FAR void *arg)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)arg;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
char devname[DEV_NAMELEN];
|
||||
|
||||
DEBUGASSERT(priv != NULL);
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
uvdbg("crefs: %d\n", priv->crefs);
|
||||
|
||||
/* Unregister the block driver */
|
||||
@ -918,12 +933,12 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
if (priv->bulkout)
|
||||
{
|
||||
DRVR_EPFREE(priv->hub->drvr, priv->bulkout);
|
||||
DRVR_EPFREE(hport->drvr, priv->bulkout);
|
||||
}
|
||||
|
||||
if (priv->bulkin)
|
||||
{
|
||||
DRVR_EPFREE(priv->hub->drvr, priv->bulkin);
|
||||
DRVR_EPFREE(hport->drvr, priv->bulkin);
|
||||
}
|
||||
|
||||
/* Free any transfer buffers */
|
||||
@ -936,7 +951,7 @@ static void usbhost_destroy(FAR void *arg)
|
||||
|
||||
/* Disconnect the USB host device */
|
||||
|
||||
DRVR_DISCONNECT(priv->hub->drvr);
|
||||
DRVR_DISCONNECT(hport->drvr);
|
||||
|
||||
/* And free the class instance. Hmmm.. this may execute on the worker
|
||||
* thread and the work structure is part of what is getting freed. That
|
||||
@ -974,7 +989,7 @@ static void usbhost_destroy(FAR void *arg)
|
||||
static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
FAR const uint8_t *configdesc, int desclen)
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
FAR struct usb_cfgdesc_s *cfgdesc;
|
||||
FAR struct usb_desc_s *desc;
|
||||
FAR struct usbhost_epdesc_s bindesc;
|
||||
@ -983,9 +998,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
uint8_t found = 0;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hub &&
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport &&
|
||||
configdesc != NULL && desclen >= sizeof(struct usb_cfgdesc_s));
|
||||
hub = priv->usbclass.hub;
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Keep the compiler from complaining about uninitialized variables */
|
||||
|
||||
@ -1075,12 +1090,13 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* Save the bulk OUT endpoint information */
|
||||
|
||||
boutdesc.hport = hport;
|
||||
boutdesc.addr = epdesc->addr & USB_EP_ADDR_NUMBER_MASK;
|
||||
boutdesc.in = false;
|
||||
boutdesc.funcaddr = hub->funcaddr;
|
||||
boutdesc.xfrtype = USB_EP_ATTR_XFER_BULK;
|
||||
boutdesc.interval = epdesc->interval;
|
||||
boutdesc.mxpacketsize = usbhost_getle16(epdesc->mxpacketsize);
|
||||
|
||||
uvdbg("Bulk OUT EP addr:%d mxpacketsize:%d\n",
|
||||
boutdesc.addr, boutdesc.mxpacketsize);
|
||||
}
|
||||
@ -1102,9 +1118,9 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* Save the bulk IN endpoint information */
|
||||
|
||||
bindesc.hport = hport;
|
||||
bindesc.addr = epdesc->addr & USB_EP_ADDR_NUMBER_MASK;
|
||||
bindesc.in = 1;
|
||||
bindesc.funcaddr = hub->funcaddr;
|
||||
bindesc.xfrtype = USB_EP_ATTR_XFER_BULK;
|
||||
bindesc.interval = epdesc->interval;
|
||||
bindesc.mxpacketsize = usbhost_getle16(epdesc->mxpacketsize);
|
||||
@ -1151,18 +1167,18 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
|
||||
|
||||
/* We are good... Allocate the endpoints */
|
||||
|
||||
ret = DRVR_EPALLOC(priv->hub->drvr, &boutdesc, &priv->bulkout);
|
||||
ret = DRVR_EPALLOC(hport->drvr, &boutdesc, &priv->bulkout);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to allocate Bulk OUT endpoint\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = DRVR_EPALLOC(priv->hub->drvr, &bindesc, &priv->bulkin);
|
||||
ret = DRVR_EPALLOC(hport->drvr, &bindesc, &priv->bulkin);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to allocate Bulk IN endpoint\n");
|
||||
(void)DRVR_EPFREE(priv->hub->drvr, priv->bulkout);
|
||||
(void)DRVR_EPFREE(hport->drvr, priv->bulkout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1553,8 +1569,13 @@ static void usbhost_putbe32(uint8_t *dest, uint32_t val)
|
||||
|
||||
static inline int usbhost_talloc(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
DEBUGASSERT(priv && priv->tbuffer == NULL);
|
||||
return DRVR_ALLOC(priv->hub->drvr, &priv->tbuffer, &priv->tbuflen);
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL &&
|
||||
priv->tbuffer == NULL);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
return DRVR_ALLOC(hport->drvr, &priv->tbuffer, &priv->tbuflen);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -1574,13 +1595,15 @@ static inline int usbhost_talloc(FAR struct usbhost_state_s *priv)
|
||||
|
||||
static inline int usbhost_tfree(FAR struct usbhost_state_s *priv)
|
||||
{
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
int result = OK;
|
||||
DEBUGASSERT(priv);
|
||||
|
||||
DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL);
|
||||
|
||||
if (priv->tbuffer)
|
||||
{
|
||||
DEBUGASSERT(priv->hub->drvr);
|
||||
result = DRVR_FREE(priv->hub->drvr, priv->tbuffer);
|
||||
hport = priv->usbclass.hport;
|
||||
result = DRVR_FREE(hport->drvr, priv->tbuffer);
|
||||
priv->tbuffer = NULL;
|
||||
priv->tbuflen = 0;
|
||||
}
|
||||
@ -1633,8 +1656,7 @@ static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *pri
|
||||
* USB ports and multiple USB devices simultaneously connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - The hub that manages the new class instance.
|
||||
* port - The hub port index
|
||||
* hport - The hub port that manages the new class instance.
|
||||
* id - In the case where the device supports multiple base classes,
|
||||
* subclasses, or protocols, this specifies which to configure for.
|
||||
*
|
||||
@ -1642,13 +1664,13 @@ static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *pri
|
||||
* On success, this function will return a non-NULL instance of struct
|
||||
* usbhost_class_s that can be used by the USB host driver to communicate
|
||||
* with the USB host class. NULL is returned on failure; this function
|
||||
* will fail only if the hub input parameter is NULL or if there are
|
||||
* will fail only if the hport input parameter is NULL or if there are
|
||||
* insufficient resources to create another USB host class instance.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct usbhost_class_s *
|
||||
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
usbhost_create(FAR struct usbhost_hubport_s *hport,
|
||||
FAR const struct usbhost_id_s *id)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
@ -1668,8 +1690,7 @@ usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
{
|
||||
/* Initialize class method function pointers */
|
||||
|
||||
priv->usbclass.hub = hub;
|
||||
priv->usbclass.port = port;
|
||||
priv->usbclass.hport = hport;
|
||||
priv->usbclass.connect = usbhost_connect;
|
||||
priv->usbclass.disconnected = usbhost_disconnected;
|
||||
|
||||
@ -1952,11 +1973,16 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer,
|
||||
size_t startsector, unsigned int nsectors)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
ssize_t ret = 0;
|
||||
int result;
|
||||
|
||||
DEBUGASSERT(inode && inode->i_private);
|
||||
priv = (FAR struct usbhost_state_s *)inode->i_private;
|
||||
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
uvdbg("startsector: %d nsectors: %d sectorsize: %d\n",
|
||||
startsector, nsectors, priv->blocksize);
|
||||
|
||||
@ -1999,19 +2025,19 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer,
|
||||
/* Construct and send the CBW */
|
||||
|
||||
usbhost_readcbw(startsector, priv->blocksize, nsectors, cbw);
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)cbw, USBMSC_CBW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the user data */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
buffer, priv->blocksize * nsectors);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the CSW */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, USBMSC_CSW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
@ -2052,13 +2078,18 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe
|
||||
size_t startsector, unsigned int nsectors)
|
||||
{
|
||||
FAR struct usbhost_state_s *priv;
|
||||
FAR struct usbhost_hubport_s *hport;
|
||||
ssize_t ret;
|
||||
int result;
|
||||
|
||||
uvdbg("sector: %d nsectors: %d sectorsize: %d\n");
|
||||
|
||||
DEBUGASSERT(inode && inode->i_private);
|
||||
priv = (FAR struct usbhost_state_s *)inode->i_private;
|
||||
|
||||
DEBUGASSERT(priv->usbclass.hport);
|
||||
hport = priv->usbclass.hport;
|
||||
|
||||
/* Check if the mass storage device is still connected */
|
||||
|
||||
if (priv->disconnected)
|
||||
@ -2092,19 +2123,19 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe
|
||||
/* Construct and send the CBW */
|
||||
|
||||
usbhost_writecbw(startsector, priv->blocksize, nsectors, cbw);
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)cbw, USBMSC_CBW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Send the user data */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkout,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkout,
|
||||
(uint8_t*)buffer, priv->blocksize * nsectors);
|
||||
if (result == OK)
|
||||
{
|
||||
/* Receive the CSW */
|
||||
|
||||
result = DRVR_TRANSFER(priv->hub->drvr, priv->bulkin,
|
||||
result = DRVR_TRANSFER(hport->drvr, priv->bulkin,
|
||||
priv->tbuffer, USBMSC_CSW_SIZEOF);
|
||||
if (result == OK)
|
||||
{
|
||||
|
@ -82,7 +82,6 @@
|
||||
* reg - The USB host class registry entry previously obtained from a call to
|
||||
* usbhost_findclass().
|
||||
* hub - The hub that manages the new class instance.
|
||||
* port - The hub port index
|
||||
* id - In the case where the device supports multiple base classes, subclasses, or
|
||||
* protocols, this specifies which to configure for.
|
||||
*
|
||||
@ -100,7 +99,7 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#define CLASS_CREATE(reg,hub,port,id) ((reg)->create(hub,port,id))
|
||||
#define CLASS_CREATE(reg,hub,id) ((reg)->create(hub,id))
|
||||
|
||||
/************************************************************************************
|
||||
* Name: CLASS_CONNECT
|
||||
@ -268,12 +267,6 @@
|
||||
|
||||
#define DRVR_GETDEVINFO(drvr,devinfo) ((drvr)->getdevinfo(drvr,devinfo))
|
||||
|
||||
/* struct usbhost_devinfo_s speed settings */
|
||||
|
||||
#define DEVINFO_SPEED_LOW 0
|
||||
#define DEVINFO_SPEED_FULL 1
|
||||
#define DEVINFO_SPEED_HIGH 2
|
||||
|
||||
/************************************************************************************
|
||||
* Name: DRVR_EPALLOC
|
||||
*
|
||||
@ -566,7 +559,7 @@ struct usbhost_id_s
|
||||
* connected to the USB port.
|
||||
*/
|
||||
|
||||
struct usbhost_hub_s; /* Forward reference to the hub state structure */
|
||||
struct usbhost_hubport_s; /* Forward reference to the hub state structure */
|
||||
struct usbhost_class_s; /* Forward reference to the class state structure */
|
||||
struct usbhost_registry_s
|
||||
{
|
||||
@ -575,7 +568,7 @@ struct usbhost_registry_s
|
||||
* provide those instances in write-able memory (RAM).
|
||||
*/
|
||||
|
||||
struct usbhost_registry_s *flink;
|
||||
struct usbhost_registry_s *flink;
|
||||
|
||||
/* This is a callback into the class implementation. It is used to (1) create
|
||||
* a new instance of the USB host class state and to (2) bind a USB host driver
|
||||
@ -584,15 +577,14 @@ struct usbhost_registry_s
|
||||
* simultaneously connected (see the CLASS_CREATE() macro above).
|
||||
*/
|
||||
|
||||
FAR struct usbhost_class_s *(*create)(FAR struct usbhost_hub_s *hub,
|
||||
uint8_t port,
|
||||
FAR const struct usbhost_id_s *id);
|
||||
FAR struct usbhost_class_s *(*create)(FAR struct usbhost_hubport_s *hub,
|
||||
FAR const struct usbhost_id_s *id);
|
||||
|
||||
/* This information uniquely identifies the USB host class implementation that
|
||||
* goes with a specific USB device.
|
||||
*/
|
||||
|
||||
uint8_t nids; /* Number of IDs in the id[] array */
|
||||
uint8_t nids; /* Number of IDs in the id[] array */
|
||||
FAR const struct usbhost_id_s *id; /* An array of ID info. Actual dimension is nids */
|
||||
};
|
||||
|
||||
@ -604,34 +596,41 @@ struct usbhost_registry_s
|
||||
|
||||
typedef FAR void *usbhost_ep_t;
|
||||
|
||||
/* Every class connects to the host controller driver (HCD) via a hub. That
|
||||
* may be an external hub or the internal, root hub. The root hub is managed
|
||||
* by the HCD. This structure provides for the linkages in that event that
|
||||
* an external hub.
|
||||
/* In the hierarchy of things, there is the host control driver (HCD),
|
||||
* represented by struct usbhost_driver_s. Connected to the HCD are one
|
||||
* or more hubs. At a minimum, the root hub is always present. Each hub
|
||||
* has from 1 to 4 ports.
|
||||
|
||||
/* Every class connects to the host controller driver (HCD) via a port on a
|
||||
* hub. That hub may be an external hub or the internal, root hub. The
|
||||
* root hub is managed by the HCD. This structure describes that state of
|
||||
* that port and provides the linkage to the parent hub in that event that
|
||||
* the port is on an external hub.
|
||||
*/
|
||||
|
||||
struct usbhost_hub_s
|
||||
struct usbhost_hubport_s
|
||||
{
|
||||
FAR struct usbhost_driver_s *drvr; /* Common host driver */
|
||||
usbhost_ep_t ep0; /* Control endpoint, ep0 */
|
||||
FAR struct usbhost_driver_s *drvr; /* Common host driver */
|
||||
#ifdef CONFIG_USBHOST_HUB
|
||||
FAR struct usbhost_hub_s *parent; /* Parent hub */
|
||||
FAR struct usb_hubtt_s *tt; /* Transaction translator hub */
|
||||
FAR struct usbhost_hubport_s *parent; /* Parent hub (NULL=root hub) */
|
||||
#endif
|
||||
uint8_t funcaddr; /* Device function address */
|
||||
uint8_t speed; /* Device speed */
|
||||
usbhost_ep_t ep0; /* Control endpoint, ep0 */
|
||||
uint8_t port; /* Hub port index */
|
||||
uint8_t funcaddr; /* Device function address */
|
||||
uint8_t speed; /* Device speed */
|
||||
};
|
||||
|
||||
/* struct usbhost_class_s provides access from the USB host driver to the USB host
|
||||
* class implementation.
|
||||
/* struct usbhost_class_s provides access from the USB host driver to the
|
||||
* USB host class implementation.
|
||||
*/
|
||||
|
||||
struct usbhost_class_s
|
||||
{
|
||||
FAR struct usbhost_hub_s *hub; /* The hub used by this class instance */
|
||||
#ifdef CONFIG_USBHOST_HUB
|
||||
uint8_t port; /* Hub port index */
|
||||
#endif
|
||||
/* Class instances are associated with devices connected on one port on a
|
||||
* hub and are represented by this structure.
|
||||
*/
|
||||
|
||||
FAR struct usbhost_hubport_s *hport; /* The port used by this class instance */
|
||||
|
||||
/* Provides the configuration descriptor to the class. The configuration
|
||||
* descriptor contains critical information needed by the class in order to
|
||||
@ -654,24 +653,14 @@ struct usbhost_class_s
|
||||
|
||||
struct usbhost_epdesc_s
|
||||
{
|
||||
#ifdef CONFIG_USBHOST_HUB
|
||||
FAR struct usbhost_hub_s *hub; /* Hub that manages the endpoint */
|
||||
#endif
|
||||
FAR struct usbhost_hubport_s *hport; /* Hub port that supports the endpoint */
|
||||
uint8_t addr; /* Endpoint address */
|
||||
bool in; /* Direction: true->IN */
|
||||
uint8_t funcaddr; /* USB address of function containing endpoint */
|
||||
uint8_t xfrtype; /* Transfer type. See USB_EP_ATTR_XFER_* in usb.h */
|
||||
uint8_t interval; /* Polling interval */
|
||||
uint16_t mxpacketsize; /* Max packetsize */
|
||||
};
|
||||
|
||||
/* This structure provides information about the connected device */
|
||||
|
||||
struct usbhost_devinfo_s
|
||||
{
|
||||
uint8_t speed:2; /* Device speed: 0=low, 1=full, 2=high */
|
||||
};
|
||||
|
||||
/* struct usbhost_connection_s provides as interface between platform-specific
|
||||
* connection monitoring and the USB host driver connection and enumeration
|
||||
* logic.
|
||||
@ -724,11 +713,6 @@ struct usbhost_driver_s
|
||||
int (*ep0configure)(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
|
||||
uint8_t funcaddr, uint16_t maxpacketsize);
|
||||
|
||||
/* Get information about the connected device */
|
||||
|
||||
int (*getdevinfo)(FAR struct usbhost_driver_s *drvr,
|
||||
FAR struct usbhost_devinfo_s *devinfo);
|
||||
|
||||
/* Allocate and configure an endpoint. */
|
||||
|
||||
int (*epalloc)(FAR struct usbhost_driver_s *drvr,
|
||||
@ -993,7 +977,6 @@ int usbhost_wlaninit(void);
|
||||
*
|
||||
* Input Parameters:
|
||||
* hub - The hub that manages the new class.
|
||||
* port - The hub port index
|
||||
* devclass - If the class driver for the device is successful located
|
||||
* and bound to the hub, the allocated class instance is returned into
|
||||
* this caller-provided memory location.
|
||||
@ -1009,7 +992,7 @@ int usbhost_wlaninit(void);
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
|
||||
int usbhost_enumerate(FAR struct usbhost_hubport_s *hub,
|
||||
FAR struct usbhost_class_s **devclass);
|
||||
|
||||
#undef EXTERN
|
||||
|
Loading…
Reference in New Issue
Block a user