From 2ea7a83bf534f5305b701becfb6accd148591063 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 20 Apr 2015 16:50:32 -0600 Subject: [PATCH] USB hub: Move port index out of hub structure and into class structure --- drivers/usbhost/usbhost_enumerate.c | 11 ++++---- drivers/usbhost/usbhost_hidkbd.c | 9 ++++--- drivers/usbhost/usbhost_hidmouse.c | 9 ++++--- drivers/usbhost/usbhost_hub.c | 41 +++++++++++++---------------- drivers/usbhost/usbhost_storage.c | 9 ++++--- include/nuttx/usb/usbhost.h | 15 ++++++----- 6 files changed, 52 insertions(+), 42 deletions(-) diff --git a/drivers/usbhost/usbhost_enumerate.c b/drivers/usbhost/usbhost_enumerate.c index 899afd5274f..ea9c7f12d24 100644 --- a/drivers/usbhost/usbhost_enumerate.c +++ b/drivers/usbhost/usbhost_enumerate.c @@ -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); diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index ce70f0dc465..c9d93d6d801 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -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; diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index d1084444334..aa5946a9675 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -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; diff --git a/drivers/usbhost/usbhost_hub.c b/drivers/usbhost/usbhost_hub.c index e8caa678063..435f5c964ff 100644 --- a/drivers/usbhost/usbhost_hub.c +++ b/drivers/usbhost/usbhost_hub.c @@ -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) */ diff --git a/drivers/usbhost/usbhost_storage.c b/drivers/usbhost/usbhost_storage.c index 2289e8dc526..a34f96d92f5 100644 --- a/drivers/usbhost/usbhost_storage.c +++ b/drivers/usbhost/usbhost_storage.c @@ -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; diff --git a/include/nuttx/usb/usbhost.h b/include/nuttx/usb/usbhost.h index c8df47c5957..770f81bfea0 100644 --- a/include/nuttx/usb/usbhost.h +++ b/include/nuttx/usb/usbhost.h @@ -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