USB hub: Move port index out of hub structure and into class structure

This commit is contained in:
Gregory Nutt 2015-04-20 16:50:32 -06:00
parent 4aeb5e549c
commit 2ea7a83bf5
6 changed files with 52 additions and 42 deletions

View File

@ -71,7 +71,7 @@ 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,
FAR struct usbhost_id_s *id);
static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub,
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);
@ -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,
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 **usbclass)
@ -242,7 +242,7 @@ static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub,
*/
ret = -ENOMEM;
devclass = CLASS_CREATE(reg, hub, id);
devclass = CLASS_CREATE(reg, hub, port, id);
uvdbg("CLASS_CREATE: %p\n", devclass);
if (devclass != NULL)
{
@ -288,6 +288,7 @@ static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub,
*
* 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.
@ -303,7 +304,7 @@ static inline int usbhost_classbind(FAR struct usbhost_hub_s *hub,
*
*******************************************************************************/
int usbhost_enumerate(FAR struct usbhost_hub_s *hub,
int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR struct usbhost_class_s **devclass)
{
FAR struct usb_ctrlreq_s *ctrlreq = NULL;
@ -535,7 +536,7 @@ int usbhost_enumerate(FAR struct usbhost_hub_s *hub,
* will begin configuring the device.
*/
ret = usbhost_classbind(hub, buffer, cfglen, &id, devclass);
ret = usbhost_classbind(hub, port, buffer, cfglen, &id, devclass);
if (ret != OK)
{
udbg("ERROR: usbhost_classbind returned %d\n", ret);

View File

@ -321,8 +321,9 @@ 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,
FAR const struct usbhost_id_s *id);
static struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id);
/* struct usbhost_class_s methods */
@ -1775,6 +1776,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
*
* Input Parameters:
* 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.
*
@ -1788,7 +1790,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
****************************************************************************/
static FAR struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub,
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id)
{
FAR struct usbhost_state_s *priv;
@ -1809,6 +1811,7 @@ static FAR struct usbhost_class_s *
/* Initialize class method function pointers */
priv->usbclass.hub = hub;
priv->usbclass.port = port;
priv->usbclass.connect = usbhost_connect;
priv->usbclass.disconnected = usbhost_disconnected;

View File

@ -369,8 +369,9 @@ 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,
FAR const struct usbhost_id_s *id);
static struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id);
/* struct usbhost_class_s methods */
@ -1847,6 +1848,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
*
* Input Parameters:
* 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.
*
@ -1860,7 +1862,7 @@ static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
****************************************************************************/
static FAR struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub,
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id)
{
FAR struct usbhost_state_s *priv;
@ -1881,6 +1883,7 @@ static FAR struct usbhost_class_s *
/* Initialize class method function pointers */
priv->usbclass.hub = hub;
priv->usbclass.port = port;
priv->usbclass.connect = usbhost_connect;
priv->usbclass.disconnected = usbhost_disconnected;

View File

@ -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 *drvr,
FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id);
/* struct usbhost_class_s methods */
@ -290,26 +290,20 @@ static inline FAR struct usbhost_hub_s *
struct usbhost_epdesc_s epdesc;
int ret;
child->drvr = drvr;
child->parent = parent;
child->tt = NULL;
child->funcaddr = usbhost_allocaddr();
child->speed = speed;
child->rhport = 0;
child->drvr = drvr;
child->parent = parent;
child->tt = NULL;
child->funcaddr = usbhost_allocaddr();
child->speed = speed;
if (!ROOTHUB(parent))
if (parent->tt != NULL)
{
if (parent->tt != NULL)
{
child->tt = parent->tt;
child->rhport = parent->rhport;
}
else if ((child->speed != USB_SPEED_HIGH) &&
(parent->speed == USB_SPEED_HIGH))
{
child->tt = &priv->tt;
child->rhport = port;
}
child->tt = parent->tt;
}
else if ((child->speed != USB_SPEED_HIGH) &&
(parent->speed == USB_SPEED_HIGH))
{
child->tt = &priv->tt;
}
epdesc.hub = child;
@ -1029,7 +1023,8 @@ static void usbhost_hubevent(FAR void *arg)
udbg("ERROR: Failed to allocated class\n");
uvdbg("enumerate port %d speed %d\n", port, speed);
ret = usbhost_enumerate(newhub, &priv->childclass[port]);
ret = usbhost_enumerate(newhub, port,
&priv->childclass[port]);
if (ret != OK)
{
udbg("ERROR: Failed to enumerate port %d: %d\n",
@ -1163,6 +1158,7 @@ static void usbhost_callback(FAR void *arg, int result)
*
* Input Parameters:
* 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.
*
@ -1176,7 +1172,7 @@ static void usbhost_callback(FAR void *arg, int result)
****************************************************************************/
static FAR struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub,
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id)
{
FAR struct usbhost_hubclass_s *alloc;
@ -1198,6 +1194,7 @@ static FAR struct usbhost_class_s *
hubclass = &alloc->hubclass;
hubclass->hub = hub;
hubclass->port = port;
hubclass->connect = usbhost_connect;
hubclass->disconnected = usbhost_disconnected;
@ -1225,7 +1222,7 @@ static FAR struct usbhost_class_s *
/* The initial reference count is 1... One reference is held by the driver */
priv->crefs = 1;
priv->crefs = 1;
/* Initialize semaphores (this works okay in the interrupt context) */

View File

@ -227,8 +227,9 @@ 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,
FAR const struct usbhost_id_s *id);
static struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id);
/* struct usbhost_class_s methods */
@ -1633,6 +1634,7 @@ static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *pri
*
* Input Parameters:
* 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.
*
@ -1646,7 +1648,7 @@ static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *pri
****************************************************************************/
static FAR struct usbhost_class_s *
usbhost_create(FAR struct usbhost_hub_s *hub,
usbhost_create(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR const struct usbhost_id_s *id)
{
FAR struct usbhost_state_s *priv;
@ -1667,6 +1669,7 @@ usbhost_create(FAR struct usbhost_hub_s *hub,
/* Initialize class method function pointers */
priv->usbclass.hub = hub;
priv->usbclass.port = port;
priv->usbclass.connect = usbhost_connect;
priv->usbclass.disconnected = usbhost_disconnected;

View File

@ -82,6 +82,7 @@
* 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.
*
@ -99,7 +100,7 @@
*
************************************************************************************/
#define CLASS_CREATE(reg,hub,id) ((reg)->create(hub,id))
#define CLASS_CREATE(reg,hub,port,id) ((reg)->create(hub,port,id))
/************************************************************************************
* Name: CLASS_CONNECT
@ -584,6 +585,7 @@ struct usbhost_registry_s
*/
FAR struct usbhost_class_s *(*create)(FAR struct usbhost_hub_s *hub,
uint8_t port,
FAR const struct usbhost_id_s *id);
/* This information uniquely identifies the USB host class implementation that
@ -618,7 +620,6 @@ struct usbhost_hub_s
#endif
uint8_t funcaddr; /* Device function address */
uint8_t speed; /* Device speed */
uint8_t rhport; /* Root hub port index */
};
/* struct usbhost_class_s provides access from the USB host driver to the USB host
@ -627,9 +628,10 @@ struct usbhost_hub_s
struct usbhost_class_s
{
/* The hub used by this class instance */
FAR struct usbhost_hub_s *hub;
FAR struct usbhost_hub_s *hub; /* The hub used by this class instance */
#ifdef CONFIG_USBHOST_HUB
uint8_t port; /* Hub port index */
#endif
/* Provides the configuration descriptor to the class. The configuration
* descriptor contains critical information needed by the class in order to
@ -991,6 +993,7 @@ 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.
@ -1006,7 +1009,7 @@ int usbhost_wlaninit(void);
*
*******************************************************************************/
int usbhost_enumerate(FAR struct usbhost_hub_s *hub,
int usbhost_enumerate(FAR struct usbhost_hub_s *hub, uint8_t port,
FAR struct usbhost_class_s **devclass);
#undef EXTERN