usb: driver-model fixes and dm support sunxi-ehci.c
Subsystems (3)
v2 cover usb: driver-model fixes and dm support sunxi-ehci.c
Hi Simon and Marek,
Here is v2 of my driver-model fixes and dm support for sunxi-ehci.c set.
Changes since v1:
-Improved the commit mesg for "dm: usb: Copy over usb_device values from
usb_scan_device() to final usb_device" adding that doing select config twice does not work for (some) usb-1 devices plugged into a usb-2 hub.
-Added a new patch changing usb_get_bus to make it easier to use for
callers.
-Replace "dm: usb: Use controller_dev in dm ehci code" with
"dm: usb: Use usb_get_bus in dm ehci code"
-Replace "dm: usb: Store usb_device parent pointer in usb_device" with
"dm: usb: Fix finding of first upstream usb-2 hub in the ehci dm code"
-"sunxi: ehci: Convert to the driver-model"
-Added comments describing the various fields in struct ehci_sunxi_priv -Dropped the empty ehci_usb_ofdata_to_platdata() function
As discussed before the plan is for patches 1-8 to go upstream through the dm tree, and then I'll take patch 9 upstream through the sunxi tree as that depends on some pending sunxi changes.
Regards,
Hans
PATCH v2 1/9 dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device
Currently we copy over a number of usb_device values stored in the on stack struct usb_device probed in usb_scan_device() to the final driver-model managed struct usb_device in usb_child_pre_probe() through usb_device_platdata, and then call usb_select_config() to fill in the rest.
There are 3 problems with this approach:
1) It does not fill in enough fields before calling usb_select_config(), specifically it does not fill in ep0's maxpacketsize causing a div by zero exception in the ehci driver.
2) It unnecessarily redoes a number of usb requests making usb probing slower
3) Calling usb_select_config() a second time fails on some usb-1 devices plugged into usb-2 hubs, causing u-boot to not recognize these devices.
This commit fixes these issues by removing the usb_select_config() call from usb_child_pre_probe(), and instead of copying over things field by field through usb_device_platdata, store a pointer to the in stack usb_device (which is still valid when usb_child_pre_probe() gets called) and copy over the entire struct.
--- drivers/usb/host/usb-uclass.c | 27 ++++++--------------------- include/usb.h | 5 +---- 2 files changed, 7 insertions(+), 25 deletions(-)
drivers/usb/host/usb-uclass.c +6 -21
@@ -535,12 +535,7 @@ int usb_scan_device(struct udevice *parent, int port, } plat =dev_get_parent_platdata (dev);debug ("%s: Probing '%s', plat=%p\n" , __func__, dev->name, plat); - plat->devnum = udev->devnum; - plat->speed = udev->speed; - plat->slot_id = udev->slot_id; - plat->portnr = port; -debug ("** device '%s': stashing slot_id=%d\n" , dev->name, - plat->slot_id); + plat->udev = udev; priv->next_addr++; ret =device_probe (dev);if (ret) {
@@ -599,25 +594,15 @@ int usb_get_bus(struct udevice *dev, struct udevice **busp)int usb_child_pre_probe (struct udevice *dev) { -struct udevice *bus;struct usb_device *udev =dev_get_parentdata (dev);struct usb_dev_platdata *plat =dev_get_parent_platdata (dev); -int ret; - ret =usb_get_bus (dev, &bus); -if (ret) -return ret; - udev->controller_dev = bus; +/* +* Copy over all the values set in the on stack struct usb_device in +* usb_scan_device() to our final struct usb_device for this dev. +*/ + *udev = *(plat->udev); udev->dev = dev; - udev->devnum = plat->devnum; - udev->slot_id = plat->slot_id; - udev->portnr = plat->portnr; - udev->speed = plat->speed; -debug ("** device '%s': getting slot_id=%d\n" , dev->name, plat->slot_id); - - ret =usb_select_config (udev); -if (ret) -return ret;return 0 ; }
include/usb.h +1 -4
@@ -581,10 +581,7 @@ struct usb_platdata {*/ struct usb_dev_platdata {struct usb_device_id id; -enum usb_device_speed speed; -int devnum; -int slot_id; -int portnr;/* Hub port number, 1..n */ +struct usb_device *udev;#ifdef CONFIG_SANDBOX struct usb_string *strings;/* NULL-terminated list of descriptor pointers */
Signature · 1 line
2.3.6
PATCH v2 2/9 dm: usb: Make usb_get_bus easier to use for callers
In reply to Hans de GoedeMake usb_get_bus easier to use for callers, by directly returning the bus rather then returning it via a pass-by-ref argument.
This also removes the error checking from the single current caller, as we alreayd have an assert() for bus not being NULL in usb_get_bus().
--- drivers/usb/host/usb-uclass.c | 11 +++-------- include/usb.h | 7 +++---- 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/usb/host/usb-uclass.c +3 -8
@@ -477,9 +477,7 @@ int usb_scan_device(struct udevice *parent, int port, *devp =NULL ;memset (udev,'\0' ,sizeof (*udev)); - ret =usb_get_bus (parent, &udev->controller_dev); -if (ret) -return ret; + udev->controller_dev =usb_get_bus (parent); priv =dev_get_uclass_priv (udev->controller_dev);/*
@@ -574,22 +572,19 @@ int usb_child_post_bind(struct udevice *dev)return 0 ; } -int usb_get_bus (struct udevice *dev,struct udevice **busp) +struct udevice *usb_get_bus (struct udevice *dev) {struct udevice *bus; - *busp =NULL ;for (bus = dev; bus &&device_get_uclass_id (bus) !=UCLASS_USB ; ) bus = bus->parent;if (!bus) {/* By design this cannot happen */ assert (bus);debug ("USB HUB '%s' does not have a controller\n" , dev->name); -return -EXDEV ; } - *busp = bus; -return 0 ; +return bus; }int usb_child_pre_probe (struct udevice *dev)
include/usb.h +3 -4
@@ -739,11 +739,10 @@ int usb_scan_device(struct udevice *parent, int port,* will be a device with uclass UCLASS_USB. * * @dev: Device to check -* @busp: Returns bus, or NULL if not found -* @return 0 if OK, -EXDEV is somehow this bus does not have a controller (this -* indicates a critical error in the USB stack +* @return The bus, or NULL if not found (this indicates a critical error in +* the USB stack */ -int usb_get_bus (struct udevice *dev,struct udevice **busp); +struct udevice *usb_get_bus (struct udevice *dev);/** * usb_select_config() - Set up a device ready for use
Signature · 1 line
2.3.6
PATCH v2 3/9 dm: usb: Use usb_get_bus in dm ehci code
In reply to Hans de GoedeUse usb_get_bus in dm ehci code rather then re-implementing it.
--- drivers/usb/host/ehci-hcd.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/usb/host/ehci-hcd.c +1 -8
@@ -125,14 +125,7 @@ static struct descriptor {static struct ehci_ctrl *ehci_get_ctrl (struct usb_device *udev) {#ifdef CONFIG_DM_USB -struct udevice *dev; - -/* Find the USB controller */ -for (dev = udev->dev; -device_get_uclass_id (dev) !=UCLASS_USB ; - dev = dev->parent) - ; -return dev_get_priv (dev); +return dev_get_priv (usb_get_bus (udev->dev));#else return udev->controller;#endif
Signature · 1 line
2.3.6
PATCH v2 4/9 dm: usb: Fix finding of first upstream usb-2 hub in the ehci dm code
In reply to Hans de GoedeThe ehci driver model code for finding the first upstream usb-2 hub before this commit has a number of issues:
1) "if (!ttdev->speed != USB_SPEED_HIGH)" does not work because the '!' takes presedence over the '!=' this should simply be
"if (ttdev->speed == USB_SPEED_HIGH)"
2) It makes ttdev point to the first upstream usb-2 hub, but ttdev should point to the last usb-1 device before the first usb-2 hub (when going upstream from the device), as ttdev is used to find the port of the first usb-2 hub to which the the last usb-1 device is connected.
3) parent_devnum however should be set to the devnum of the first usb-2 hub, so we need to keep pointers around to both usb_device structs.
To complicate things further during enumeration usb_device.dev will point to the parent udevice, where as during normal use it will point to the actual udevice, we must handle both cases correctly.
This commit fixes all this making usb-1 devices attached to usb-2 hubs, including usb-1 devices attached to usb-1 hubs attached to usb-2 hubs, work.
--- drivers/usb/host/ehci-hcd.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/usb/host/ehci-hcd.c +22 -12
@@ -303,23 +303,33 @@ static void ehci_update_endpt2_dev_n_port(struct usb_device *udev,* in the tree before that one! */ #ifdef CONFIG_DM_USB +/* +* When called from usb-uclass.c: usb_scan_device() udev->dev points +* to the parent udevice, not the actual udevice belonging to the +* udev as the device is not instantiated yet. So when searching +* for the first usb-2 parent start with udev->dev not +* udev->dev->parent . +*/ struct udevice *parent; +struct usb_device *uparent; + + ttdev = udev; + parent = udev->dev; + uparent =dev_get_parentdata (parent); -for (ttdev = udev; ; ) { -struct udevice *dev = ttdev->dev; +while (uparent->speed !=USB_SPEED_HIGH ) { +struct udevice *dev = parent; -if (dev->parent && -device_get_uclass_id (dev->parent) ==UCLASS_USB_HUB ) - parent = dev->parent; -else - parent =NULL ; -if (!parent) +if (device_get_uclass_id (dev->parent) !=UCLASS_USB_HUB ) { +printf ("ehci: Error cannot find high speed parent of usb-1 device\n" );return ; - ttdev =dev_get_parentdata (parent); -if (!ttdev->speed !=USB_SPEED_HIGH ) -break ; + } + + ttdev =dev_get_parentdata (dev); + parent = dev->parent; + uparent =dev_get_parentdata (parent); } - parent_devnum = ttdev->devnum; + parent_devnum = uparent->devnum;#else ttdev = udev;while (ttdev->parent && ttdev->parent->speed !=USB_SPEED_HIGH )
Signature · 1 line
2.3.6
PATCH v2 5/9 dm: usb: Set desc_before_addr from ehci dm code
In reply to Hans de GoedeWithout this usb-1 device descriptors do not get read properly.
--- drivers/usb/host/ehci-hcd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/host/ehci-hcd.c +3 -0
@@ -1579,12 +1579,15 @@ int ehci_register(struct udevice *dev, struct ehci_hccr *hccr, struct ehci_hcor *hcor, const struct ehci_ops *ops, uint tweaks, enum usb_init_type init) { + struct usb_bus_priv *priv = dev_get_uclass_priv(dev);struct ehci_ctrl *ctrl =dev_get_priv (dev);int ret;debug ("%s: dev='%s', ctrl=%p, hccr=%p, hcor=%p, init=%d\n" , __func__, dev->name, ctrl, hccr, hcor, init); + priv->desc_before_addr = true; +ehci_setup_ops (ctrl, ops); ctrl->hccr = hccr; ctrl->hcor = hcor;
Signature · 1 line
2.3.6
PATCH v2 6/9 dm: usb: Add support for interrupt queues to the dm usb code
In reply to Hans de GoedeInterrupt endpoints typically are polled for a long time by the usb controller before they return anything, so calls to submit_int_msg() can take a long time to complete this.
To avoid this the u-boot code has the an interrupt queue mechanism / API, add support for this to the driver-model usb code.
See the added doc comments for more details.
--- drivers/usb/host/usb-uclass.c | 36 ++++++++++++++++++++++++++++++++ include/usb.h | 48 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-)
drivers/usb/host/usb-uclass.c +36 -0
@@ -65,6 +65,42 @@ int submit_bulk_msg(struct usb_device *udev, unsigned long pipe, void *buffer,return ops->bulk (bus, udev, pipe, buffer, length); } +struct int_queue *create_int_queue (struct usb_device *udev, +unsigned long pipe,int queuesize,int elementsize, +void *buffer,int interval) +{ +struct udevice *bus = udev->controller_dev; +struct dm_usb_ops *ops =usb_get_ops (bus); + +if (!ops->create_int_queue) +return NULL ; + +return ops->create_int_queue (bus, udev, pipe, queuesize, elementsize, + buffer, interval); +} + +void *poll_int_queue (struct usb_device *udev,struct int_queue *queue) +{ +struct udevice *bus = udev->controller_dev; +struct dm_usb_ops *ops =usb_get_ops (bus); + +if (!ops->poll_int_queue) +return NULL ; + +return ops->poll_int_queue (bus, udev, queue); +} + +int destroy_int_queue (struct usb_device *udev,struct int_queue *queue) +{ +struct udevice *bus = udev->controller_dev; +struct dm_usb_ops *ops =usb_get_ops (bus); + +if (!ops->destroy_int_queue) +return -ENOSYS ; + +return ops->destroy_int_queue (bus, udev, queue); +} +int usb_alloc_device (struct usb_device *udev) {struct udevice *bus = udev->controller_dev;
include/usb.h +47 -1
60 lines not on this page · raw message
Signature · 1 line
2.3.6
PATCH v2 7/9 dm: usb: Prefix ehci interrupt-queue functions with _ehci_
In reply to Hans de GoedeThis is a preparation patch for adding interrupt-queue support to the ehci dm code.
--- drivers/usb/host/ehci-hcd.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/usb/host/ehci-hcd.c +25 -6
@@ -1252,9 +1252,9 @@ disable_periodic(struct ehci_ctrl *ctrl)return 0 ; } -struct int_queue * -create_int_queue (struct usb_device *dev,unsigned long pipe,int queuesize, -int elementsize,void *buffer,int interval) +static struct int_queue *_ehci_create_int_queue (struct usb_device *dev, +unsigned long pipe,int queuesize,int elementsize, +void *buffer,int interval) {struct ehci_ctrl *ctrl =ehci_get_ctrl (dev);struct int_queue *result =NULL ;
@@ -1410,7 +1410,8 @@ fail1:return NULL ; } -void *poll_int_queue (struct usb_device *dev,struct int_queue *queue) +static void *_ehci_poll_int_queue (struct usb_device *dev, +struct int_queue *queue) {struct QH *cur = queue->current;struct qTD *cur_td;
@@ -1445,8 +1446,8 @@ void *poll_int_queue(struct usb_device *dev, struct int_queue *queue) }/* Do not free buffers associated with QHs, they're owned by someone else */ -int -destroy_int_queue (struct usb_device *dev,struct int_queue *queue) +static int _ehci_destroy_int_queue (struct usb_device *dev, +struct int_queue *queue) {struct ehci_ctrl *ctrl =ehci_get_ctrl (dev);int result =-1 ;
@@ -1547,6 +1548,24 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe, {return _ehci_submit_int_msg (dev, pipe, buffer, length, interval); } + +struct int_queue *create_int_queue (struct usb_device *dev, +unsigned long pipe,int queuesize,int elementsize, +void *buffer,int interval) +{ +return _ehci_create_int_queue (dev, pipe, queuesize, elementsize, + buffer, interval); +} + +void *poll_int_queue (struct usb_device *dev,struct int_queue *queue) +{ +return _ehci_poll_int_queue (dev, queue); +} + +int destroy_int_queue (struct usb_device *dev,struct int_queue *queue) +{ +return _ehci_destroy_int_queue (dev, queue); +}#endif #ifdef CONFIG_DM_USB
Signature · 1 line
2.3.6
PATCH v2 8/9 dm: usb: Add support for interrupt queues to the dm ehci code
In reply to Hans de GoedeAdd support for interrupt queues to the dm ehci code.
--- drivers/usb/host/ehci-hcd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/usb/host/ehci-hcd.c +26 -0
@@ -1594,6 +1594,29 @@ static int ehci_submit_int_msg(struct udevice *dev, struct usb_device *udev,return _ehci_submit_int_msg (udev, pipe, buffer, length, interval); } +static struct int_queue *ehci_create_int_queue (struct udevice *dev, +struct usb_device *udev,unsigned long pipe,int queuesize, +int elementsize,void *buffer,int interval) +{ +debug ("%s: dev='%s', udev=%p\n" , __func__, dev->name, udev); +return _ehci_create_int_queue (udev, pipe, queuesize, elementsize, + buffer, interval); +} + +static void *ehci_poll_int_queue (struct udevice *dev,struct usb_device *udev, +struct int_queue *queue) +{ +debug ("%s: dev='%s', udev=%p\n" , __func__, dev->name, udev); +return _ehci_poll_int_queue (udev, queue); +} + +static int ehci_destroy_int_queue (struct udevice *dev,struct usb_device *udev, +struct int_queue *queue) +{ +debug ("%s: dev='%s', udev=%p\n" , __func__, dev->name, udev); +return _ehci_destroy_int_queue (udev, queue); +} +int ehci_register (struct udevice *dev,struct ehci_hccr *hccr,struct ehci_hcor *hcor,const struct ehci_ops *ops,uint tweaks,enum usb_init_type init)
@@ -1642,6 +1665,9 @@ struct dm_usb_ops ehci_usb_ops = { .control = ehci_submit_control_msg, .bulk = ehci_submit_bulk_msg, .interrupt = ehci_submit_int_msg, + .create_int_queue = ehci_create_int_queue, + .poll_int_queue = ehci_poll_int_queue, + .destroy_int_queue = ehci_destroy_int_queue, };#endif
Signature · 1 line
2.3.6
PATCH v2 9/9 sunxi: ehci: Convert to the driver-model
In reply to Hans de GoedeConvert sunxi-boards which use the sunxi-ehci code to the driver-model.
--- board/sunxi/Kconfig | 3 ++ drivers/usb/host/ehci-sunxi.c | 89 +++++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 29 deletions(-)
board/sunxi/Kconfig +3 -0
@@ -559,4 +559,7 @@ config DM_ETH config DM_SERIAL default y +config DM_USB + default y if !USB_MUSB_SUNXI + endif
drivers/usb/host/ehci-sunxi.c +60 -29
113 lines not on this page · raw message
Signature · 1 line
2.3.6
PATCH v2 1/9 dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device
In reply to Hans de GoedeHi Hans,
Quoted 14 lines · Hans de Goede
Currently we copy over a number of
usb_devicevalues stored in the on stack structusb_deviceprobed inusb_scan_device()to the final driver-model managed structusb_deviceinusb_child_pre_probe()throughusb_device_platdata, and then callusb_select_config()to fill in the rest.There are 3 problems with this approach:
1) It does not fill in enough fields before calling
usb_select_config(), specifically it does not fill in ep0's maxpacketsize causing a div by zero exception in the ehci driver.2) It unnecessarily redoes a number of usb requests making usb probing slower
Quoted 8 lines
3) Calling
usb_select_config()a second time fails on some usb-1 devices plugged into usb-2 hubs, causing u-boot to not recognize these devices.This commit fixes these issues by removing the
usb_select_config()call fromusb_child_pre_probe(), and instead of copying over things field by field throughusb_device_platdata, store a pointer to the in stackusb_device(which is still valid whenusb_child_pre_probe()gets called) and copy over the entire struct.
OK well you've heard my reservations. Given that we need to fix this and I don't have the inclination to do the full refactor now (to allow USB drivers to send requests without a device) I think we should go along with what you propose.
Let's make sure no one builds on it, by adding comments about the intended direction (separating out the request from the device that issues it).
Quoted 12 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/host/usb-uclass.c | 27 ++++++--------------------- include/usb.h | 5 +---- 2 files changed, 7 insertions(+), 25 deletions(-)drivers/usb/host/usb-uclass.c +0
-0
drivers/usb/host/usb-uclass.c int usb_scan_device(struct udevice *parent, int port, · line 538
Quoted 10 lines
drivers/usb/host/usb-uclass.c +1
-6@@ -535,12 +535,7 @@ int usb_scan_device(struct udevice *parent, int port, } plat =dev_get_parent_platdata (dev);debug ("%s: Probing '%s', plat=%p\n" , __func__, dev->name, plat); - plat->devnum = udev->devnum; - plat->speed = udev->speed; - plat->slot_id = udev->slot_id; - plat->portnr = port; -debug ("** device '%s': stashing slot_id=%d\n" , dev->name, - plat->slot_id); + plat->udev = udev;
This is a local variable. How can it be safe to use this pointer and then return from this function?
For now, how about putting the whole usb_device in the plat structure. I think it is a lesser evil. You can add a large TODO to fix it up.
Quoted 39 lines
drivers/usb/host/usb-uclass.c +5
-15priv->next_addr++; ret =device_probe (dev);if (ret) {@@ -599,25 +594,15 @@ int usb_get_bus(struct udevice *dev, struct udevice **busp)int usb_child_pre_probe (struct udevice *dev) { -struct udevice *bus;struct usb_device *udev =dev_get_parentdata (dev);struct usb_dev_platdata *plat =dev_get_parent_platdata (dev); -int ret; - ret =usb_get_bus (dev, &bus); -if (ret) -return ret; - udev->controller_dev = bus; +/* +* Copy over all the values set in the on stack struct usb_device in +* usb_scan_device() to our final struct usb_device for this dev. +*/ + *udev = *(plat->udev); udev->dev = dev; - udev->devnum = plat->devnum; - udev->slot_id = plat->slot_id; - udev->portnr = plat->portnr; - udev->speed = plat->speed; -debug ("** device '%s': getting slot_id=%d\n" , dev->name, plat->slot_id); - - ret =usb_select_config (udev); -if (ret) -return ret;return 0 ; }include/usb.h +0
-0
include/usb.h struct usb_platdata { · line 584
Quoted 8 lines
include/usb.h +1
-4@@ -581,10 +581,7 @@ struct usb_platdata {*/ struct usb_dev_platdata {struct usb_device_id id; -enum usb_device_speed speed; -int devnum; -int slot_id; -int portnr;/* Hub port number, 1..n */ +struct usb_device *udev;
Structure comment needs updating. I think it could do with some big hairy warnings also.
Quoted 6 lines
include/usb.h +0
-1#ifdef CONFIG_SANDBOX struct usb_string *strings;/* NULL-terminated list of descriptor pointers */ --2.3.6
Regards,
Simon
PATCH v2 3/9 dm: usb: Use usb_get_bus in dm ehci code
In reply to Hans de GoedeHi Simon,
Quoted 15 lines · Hans de Goede
Use
usb_get_busin dm ehci code rather then re-implementing it.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/host/ehci-hcd.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/usb/host/ehci-hcd.c +0
-0@@ -125,14 +125,7 @@ static struct descriptor {static struct ehci_ctrl *ehci_get_ctrl (struct usb_device *udev) {
drivers/usb/host/ehci-hcd.c static struct descriptor { · line 128
Quoted 10 lines
drivers/usb/host/ehci-hcd.c +1
-8#ifdef CONFIG_DM_USB -struct udevice *dev; - -/* Find the USB controller */ -for (dev = udev->dev; -device_get_uclass_id (dev) !=UCLASS_USB ; - dev = dev->parent) - ; -return dev_get_priv (dev); +return dev_get_priv (usb_get_bus (udev->dev));
To be safe shouldn't we check for NULL here?
Quoted 6 lines
drivers/usb/host/ehci-hcd.c +0
-1#else return udev->controller;#endif --2.3.6
Regards,
Simon
PATCH v2 2/9 dm: usb: Make usb_get_bus easier to use for callers
In reply to Hans de GoedeQuoted 12 lines · Hans de Goede
Make
usb_get_buseasier to use for callers, by directly returning the bus rather then returning it via a pass-by-ref argument.This also removes the error checking from the single current caller, as we alreayd have an
assert()for bus not being NULL inusb_get_bus().Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/host/usb-uclass.c | 11 +++-------- include/usb.h | 7 +++---- 2 files changed, 6 insertions(+), 12 deletions(-)
Quoted 45 lines
drivers/usb/host/usb-uclass.c +3
-8@@ -477,9 +477,7 @@ int usb_scan_device(struct udevice *parent, int port, *devp =NULL ;memset (udev,'\0' ,sizeof (*udev)); - ret =usb_get_bus (parent, &udev->controller_dev); -if (ret) -return ret; + udev->controller_dev =usb_get_bus (parent); priv =dev_get_uclass_priv (udev->controller_dev);/* @@ -574,22 +572,19 @@ int usb_child_post_bind(struct udevice *dev)return 0 ; } -int usb_get_bus (struct udevice *dev,struct udevice **busp) +struct udevice *usb_get_bus (struct udevice *dev) {struct udevice *bus; - *busp =NULL ;for (bus = dev; bus &&device_get_uclass_id (bus) !=UCLASS_USB ; ) bus = bus->parent;if (!bus) {/* By design this cannot happen */ assert (bus);debug ("USB HUB '%s' does not have a controller\n" , dev->name); -return -EXDEV ; } - *busp = bus; -return 0 ; +return bus; }int usb_child_pre_probe (struct udevice *dev)include/usb.h +0
-0
include/usb.h int usb_scan_device(struct udevice *parent, int port, · line 743
Quoted 8 lines
include/usb.h +2
-3@@ -739,11 +739,10 @@ int usb_scan_device(struct udevice *parent, int port,* will be a device with uclass UCLASS_USB. * * @dev: Device to check -* @busp: Returns bus, or NULL if not found -* @return 0 if OK, -EXDEV is somehow this bus does not have a controller (this -* indicates a critical error in the USB stack +* @return The bus, or NULL if not found (this indicates a critical error in +* the USB stack
) here
Quoted 9 lines
include/usb.h +1
-2*/ -int usb_get_bus (struct udevice *dev,struct udevice **busp); +struct udevice *usb_get_bus (struct udevice *dev);/** * usb_select_config() - Set up a device ready for use -- 2.3.6
PATCH v2 3/9 dm: usb: Use usb_get_bus in dm ehci code
In reply to Hans de GoedeHi Hans,
Quoted 7 lines · Hans de Goede
Use
usb_get_busin dm ehci code rather then re-implementing it.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/host/ehci-hcd.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
Quoted 7 lines
drivers/usb/host/ehci-hcd.c +0
-0@@ -125,14 +125,7 @@ static struct descriptor {static struct ehci_ctrl *ehci_get_ctrl (struct usb_device *udev) {
drivers/usb/host/ehci-hcd.c static struct descriptor { · line 128
Quoted 10 lines
drivers/usb/host/ehci-hcd.c +1
-8#ifdef CONFIG_DM_USB -struct udevice *dev; - -/* Find the USB controller */ -for (dev = udev->dev; -device_get_uclass_id (dev) !=UCLASS_USB ; - dev = dev->parent) - ; -return dev_get_priv (dev); +return dev_get_priv (usb_get_bus (udev->dev));
To be safe shouldn't we check for NULL here?
Quoted 6 lines
drivers/usb/host/ehci-hcd.c +0
-1#else return udev->controller;#endif --2.3.6
Regards,
Simon
PATCH v2 4/9 dm: usb: Fix finding of first upstream usb-2 hub in the ehci dm code
In reply to Hans de GoedeQuoted 13 lines · Hans de Goede
The ehci driver model code for finding the first upstream usb-2 hub before this commit has a number of issues:
1) "if (!ttdev->speed !=
USB_SPEED_HIGH)" does not work because the '!' takes presedence over the '!=' this should simply be
"if (ttdev->speed==USB_SPEED_HIGH)"
2) It makes ttdev point to the first upstream usb-2 hub, but ttdev should point to the last usb-1 device before the first usb-2 hub (when going upstream from the device), as ttdev is used to find the port of the first usb-2 hub to which the the last usb-1 device is connected.
3)parent_devnumhowever should be set to the devnum of the first usb-2 hub, so we need to keep pointers around to bothusb_devicestructs.
Quoted 8 lines
To complicate things further during enumeration usb_device.dev will point to the parent udevice, where as during normal use it will point to the actual udevice, we must handle both cases correctly.
This commit fixes all this making usb-1 devices attached to usb-2 hubs, including usb-1 devices attached to usb-1 hubs attached to usb-2 hubs, work.
Signed-off-by Hans de Goede <[email protected]>
I'm pleased that you understand this logic.
Quoted 57 lines
--- drivers/usb/host/ehci-hcd.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)drivers/usb/host/ehci-hcd.c +22
-13@@ -303,23 +303,33 @@ static void ehci_update_endpt2_dev_n_port(struct usb_device *udev,* in the tree before that one! */ #ifdef CONFIG_DM_USB +/* +* When called from usb-uclass.c: usb_scan_device() udev->dev points +* to the parent udevice, not the actual udevice belonging to the +* udev as the device is not instantiated yet. So when searching +* for the first usb-2 parent start with udev->dev not +* udev->dev->parent . +*/ struct udevice *parent; +struct usb_device *uparent; + + ttdev = udev; + parent = udev->dev; + uparent =dev_get_parentdata (parent); -for (ttdev = udev; ; ) { -struct udevice *dev = ttdev->dev; +while (uparent->speed !=USB_SPEED_HIGH ) { +struct udevice *dev = parent; -if (dev->parent && -device_get_uclass_id (dev->parent) ==UCLASS_USB_HUB ) - parent = dev->parent; -else - parent =NULL ; -if (!parent) +if (device_get_uclass_id (dev->parent) !=UCLASS_USB_HUB ) { +printf ("ehci: Error cannot find high speed parent of usb-1 device\n" );return ; - ttdev =dev_get_parentdata (parent); -if (!ttdev->speed !=USB_SPEED_HIGH ) -break ; + } + + ttdev =dev_get_parentdata (dev); + parent = dev->parent; + uparent =dev_get_parentdata (parent); } - parent_devnum = ttdev->devnum; + parent_devnum = uparent->devnum;#else ttdev = udev;while (ttdev->parent && ttdev->parent->speed !=USB_SPEED_HIGH ) --2.3.6
PATCH v2 3/9 dm: usb: Use usb_get_bus in dm ehci code
In reply to Simon GlassHi,
Quoted 24 lines · Simon Glass
Hi Hans,
Quoted 7 lines · Hans de Goede
Use
usb_get_busin dm ehci code rather then re-implementing it.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/host/ehci-hcd.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)Acked-by Simon Glass <[email protected]>Quoted 11 lines
drivers/usb/host/ehci-hcd.c +0
-3@@ -125,14 +125,7 @@ static struct descriptor {static struct ehci_ctrl *ehci_get_ctrl (struct usb_device *udev) {#ifdef CONFIG_DM_USB -struct udevice *dev; - -/* Find the USB controller */
Quoted 8 lines
drivers/usb/host/ehci-hcd.c static struct descriptor { · line 128
Quoted 6 lines
drivers/usb/host/ehci-hcd.c +1
-5-for (dev = udev->dev; -device_get_uclass_id (dev) !=UCLASS_USB ; - dev = dev->parent) - ; -return dev_get_priv (dev); +return dev_get_priv (usb_get_bus (udev->dev));To be safe shouldn't we check for NULL here?
That should never happen, and there already is an assert for that in usb_get_bus, or you mean dev_get_priv returning NULL.
Regards,
Hans
Quoted 11 lines
Quoted 7 lines
drivers/usb/host/ehci-hcd.c +0
-1#else return udev->controller;#endif --2.3.6
Regards,
Simon
PATCH v2 3/9 dm: usb: Use usb_get_bus in dm ehci code
Hi Hans,
Quoted 41 lines · Hans de Goede
Hi,
Quoted 27 lines · Simon Glass
Hi Hans,
Quoted 8 lines · Hans de Goede
Use
usb_get_busin dm ehci code rather then re-implementing it.Signed-off-by Hans de Goede <[email protected]>--- drivers/usb/host/ehci-hcd.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)Acked-by Simon Glass <[email protected]>Quoted 12 lines
drivers/usb/host/ehci-hcd.c +0
-4@@ -125,14 +125,7 @@ static struct descriptor {static struct ehci_ctrl *ehci_get_ctrl (struct usb_device *udev) {#ifdef CONFIG_DM_USB -struct udevice *dev; - -/* Find the USB controller */ - for (dev = udev->dev;Quoted 8 lines
drivers/usb/host/ehci-hcd.c static struct descriptor { · line 128
Quoted 5 lines
drivers/usb/host/ehci-hcd.c +1
-4-device_get_uclass_id (dev) !=UCLASS_USB ; - dev = dev->parent) - ; -return dev_get_priv (dev); +return dev_get_priv (usb_get_bus (udev->dev));To be safe shouldn't we check for NULL here?
Quoted 2 lines
That should never happen, and there already is an assert for that in
usb_get_bus, or you meandev_get_privreturning NULL.
No I mean usb_get_bus(). It could be hard to debug if it does happen, but hopefully the first thing they do is turn on DEBUG in that file and see the assert().
I think it is OK.
Regards,
Simon