Skip to contentSkip to conversation

dm usb fixes + sunxi dm ehci support

PATCH Superseded Hans de Goede 2 participants 28 messages May 5, 2015 – May 9, 2015

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover dm usb fixes + sunxi dm ehci support

Hi Simon, et al,

Here is v4 of my dm usb + driver-model support for the sunxi-ehci code set.

New since v2 (v3 for one patch) is that this now no longer breaks sandbox usb emul devices. I had to reshuffle the order of 2 patches to fix this cleanly, and I've also added some extra comments to the last patch of the set as requested by Ian.

So please take all patches from this v4 posting when merging.

Thanks & Regards,

Hans

#1 lore raw

PATCH v4 1/9 dm: usb: Make usb_get_bus easier to use for callers

Make 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 current callers, as we already have an assert() for bus not being NULL in usb_get_bus().

---
Changes in v2:
-New patch in v2 of this patch-set
Changes in v4:
-Moved this patch to be the first of the patch-set so that it can be used in
"dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device"

---
 drivers/usb/host/usb-uclass.c | 17 ++++-------------
 include/usb.h                 |  7 +++----
 2 files changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/usb-uclass.c +4 -13
index 8dc1823..ba7d32a 100644
@@ -476,9 +476,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);
 
 	/*
@@ -578,35 +576,28 @@ 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)
 {
-	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;
+	udev->controller_dev = usb_get_bus(dev);
 	udev->dev = dev;
 	udev->devnum = plat->devnum;
 	udev->slot_id = plat->slot_id;
include/usb.h +3 -4
index 1984e8f..6207d36 100644
@@ -742,11 +742,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
#3 lore raw

PATCH v4 2/9 dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device

In reply to Hans de Goede

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.

*) Except for devices which are explictly instantiated through device-tree rather then discovered through usb_scan_device() such as emulated usb devices in the sandbox.

---
Changes in v3:
-Add a big fat comment to warn that plat->udev is for usb-uclass.c internal
use only
Changes in v4:
-Fix sandbox emul usb device breakage

---
 drivers/usb/host/usb-uclass.c | 43 ++++++++++++++++++++++++++++---------------
 include/usb.h                 | 17 ++++++++++-------
 2 files changed, 38 insertions(+), 22 deletions(-)
drivers/usb/host/usb-uclass.c +28 -15
index ba7d32a..c5ece58 100644
@@ -533,11 +533,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) {
@@ -597,17 +593,34 @@ int usb_child_pre_probe(struct udevice *dev)
 	struct usb_dev_platdata *plat = dev_get_parent_platdata(dev);
 	int ret;
 
-	udev->controller_dev = usb_get_bus(dev);
-	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);
+	if (plat->udev) {
+		/*
+		 * 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);
+		/* And clear plat->udev as it will not be valid for long */
+		plat->udev = NULL;
+		udev->dev = dev;
+	} else {
+		/*
+		 * This happens with devices which are explicitly bound
+		 * instead of being discovered through usb_scan_device()
+		 * such as sandbox emul devices.
+		 */
+		udev->dev = dev;
+		udev->controller_dev = usb_get_bus(dev);
+		udev->devnum = plat->devnum;
 
-	ret = usb_select_config(udev);
-	if (ret)
-		return ret;
+		/*
+		 * udev did not go through usb_scan_device(), so we need to
+		 * select the config and read the config descriptors.
+		 */
+		ret = usb_select_config(udev);
+		if (ret)
+			return ret;
+	}
 
 	return 0;
 }
include/usb.h +10 -7
index 6207d36..4c21050 100644
@@ -571,20 +571,23 @@ struct usb_platdata {
  * This is used by sandbox to provide emulation data also.
  *
  * @id:		ID used to match this device
- * @speed:	Stores the speed associated with a USB device
  * @devnum:	Device address on the USB bus
- * @slot_id:	USB3 slot ID, which is separate from the device address
- * @portnr:	Port number of this device on its parent hub, numbered from 1
- *		(0 mean this device is the root hub)
+ * @udev:	usb-uclass internal use only do NOT use
  * @strings:	List of descriptor strings (for sandbox emulation purposes)
  * @desc_list:	List of descriptors (for sandbox emulation purposes)
  */
 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 */
+	/*
+	 * This pointer is used to pass the usb_device used in usb_scan_device,
+	 * to get the usb descriptors before the driver is known, to the
+	 * actual udevice once the driver is known and the udevice is created.
+	 * This will be NULL except during probe, do NOT use.
+	 *
+	 * This should eventually go away.
+	 */
+	struct usb_device *udev;
 #ifdef CONFIG_SANDBOX
 	struct usb_string *strings;
 	/* NULL-terminated list of descriptor pointers */
Signature · 1 line
2.3.6
#6 lore raw

PATCH v4 3/9 dm: usb: Use usb_get_bus in dm ehci code

In reply to Hans de Goede

Use usb_get_bus in dm ehci code rather then re-implementing it.

---
Changes in v2:
-New patch in v2 of this patch-set

---
 drivers/usb/host/ehci-hcd.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/usb/host/ehci-hcd.c +1 -8
index bd9861d..85adbf4 100644
@@ -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
#8 lore raw

PATCH v4 4/9 dm: usb: Fix finding of first upstream usb-2 hub in the ehci dm code

In reply to 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_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.

---
Changes in v2:
-Rewrote the fix to use driver-model logic to find the first upstream usb-2
hub rather then using the deprecated usb_device->parent pointer

---
 drivers/usb/host/ehci-hcd.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/usb/host/ehci-hcd.c +22 -12
index 85adbf4..9471bcb 100644
@@ -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
#10 lore raw

PATCH v4 5/9 dm: usb: Set desc_before_addr from ehci dm code

In reply to Hans de Goede

Without 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
index 9471bcb..46d01d4 100644
@@ -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
#12 lore raw

PATCH v4 6/9 dm: usb: Add support for interrupt queues to the dm usb code

In reply to Hans de Goede

Interrupt 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
index c5ece58..9ee25ed 100644
@@ -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
#17 lore raw

PATCH v4 7/9 dm: usb: Prefix ehci interrupt-queue functions with _ehci_

In reply to Hans de Goede

This 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
index 46d01d4..363ce38 100644
@@ -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
#20 lore raw

PATCH v4 8/9 dm: usb: Add support for interrupt queues to the dm ehci code

In reply to Hans de Goede

Add 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
index 363ce38..0e84265 100644
@@ -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
#23 lore raw

PATCH v4 9/9 sunxi: ehci: Convert to the driver-model

In reply to Hans de Goede

Convert sunxi-boards which use the sunxi-ehci code to the driver-model.

---
Changes in v4:
-Add a comment to document the setting of some priv-data members based on
the controller base-address

---
 board/sunxi/Kconfig           |  3 ++
 drivers/usb/host/ehci-sunxi.c | 93 +++++++++++++++++++++++++++++--------------
 2 files changed, 67 insertions(+), 29 deletions(-)
board/sunxi/Kconfig +3 -0
index a60d028..4ca1ac1 100644
@@ -555,4 +555,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 +64 -29

117 lines not on this page · raw message

Signature · 1 line
2.3.6
#4 lore raw

PATCH v4 2/9 dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device

In reply to Hans de Goede
Quoted 33 lines · Hans de Goede

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.

*) Except for devices which are explictly instantiated through device-tree rather then discovered through usb_scan_device() such as emulated usb devices in the sandbox.

---
Changes in v3:
-Add a big fat comment to warn that plat->udev is for usb-uclass.c internal
use only
Changes in v4:
-Fix sandbox emul usb device breakage

Quoted 4 lines
---
 drivers/usb/host/usb-uclass.c | 43 ++++++++++++++++++++++++++++---------------
 include/usb.h                 | 17 ++++++++++-------
 2 files changed, 38 insertions(+), 22 deletions(-)
#2 lore raw

PATCH v4 1/9 dm: usb: Make usb_get_bus easier to use for callers

In reply to Hans de Goede
Quoted 14 lines · Hans de Goede

Make 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 current callers, as we already have an assert() for bus not being NULL in usb_get_bus().

---
Changes in v2:
-New patch in v2 of this patch-set
Changes in v4:
-Moved this patch to be the first of the patch-set so that it can be used in
"dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device"

Quoted 4 lines
---
 drivers/usb/host/usb-uclass.c | 17 ++++-------------
 include/usb.h                 |  7 +++----
 2 files changed, 7 insertions(+), 17 deletions(-)

Applied to u-boot-dm, thanks!

#5 lore raw

PATCH v4 2/9 dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device

In reply to Simon Glass
Quoted 27 lines · Simon Glass
Quoted 26 lines · Hans de Goede

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.

*) Except for devices which are explictly instantiated through device-tree rather then discovered through usb_scan_device() such as emulated usb devices in the sandbox.

Quoted 13 lines
Quoted 11 lines

---
Changes in v3:
-Add a big fat comment to warn that plat->udev is for usb-uclass.c internal
use only
Changes in v4:
-Fix sandbox emul usb device breakage

---
 drivers/usb/host/usb-uclass.c | 43 ++++++++++++++++++++++++++++---------------
 include/usb.h                 | 17 ++++++++++-------
 2 files changed, 38 insertions(+), 22 deletions(-)

Applied to u-boot-dm, thanks!

#9 lore raw

PATCH v4 4/9 dm: usb: Fix finding of first upstream usb-2 hub in the ehci dm code

In reply to Hans de Goede
Quoted 20 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_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.

Quoted 6 lines

---
Changes in v2:
-Rewrote the fix to use driver-model logic to find the first upstream usb-2
hub rather then using the deprecated usb_device->parent pointer

Applied to u-boot-dm, thanks!

#13 lore raw

PATCH v4 6/9 dm: usb: Add support for interrupt queues to the dm usb code

In reply to Hans de Goede
Quoted 7 lines · Hans de Goede

Interrupt 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.

Quoted 8 lines

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(-)

Applied to u-boot-dm, thanks!

#24 lore raw

PATCH v4 9/9 sunxi: ehci: Convert to the driver-model

In reply to Hans de Goede
Quoted 4 lines · Hans de Goede

Convert sunxi-boards which use the sunxi-ehci code to the driver-model.

Quoted 8 lines

---
Changes in v4:
-Add a comment to document the setting of some priv-data members based on
the controller base-address

---
 board/sunxi/Kconfig           |  3 ++
 drivers/usb/host/ehci-sunxi.c | 93 +++++++++++++++++++++++++++++--------------
 2 files changed, 67 insertions(+), 29 deletions(-)

Applied to u-boot-dm, thanks!

#25 lore raw

PATCH v4 9/9 sunxi: ehci: Convert to the driver-model

Hi Hans,

Quoted 14 lines · Simon Glass
Quoted 4 lines · Hans de Goede

Convert sunxi-boards which use the sunxi-ehci code to the driver-model.

Quoted 8 lines

---
Changes in v4:
-Add a comment to document the setting of some priv-data members based on
the controller base-address

---
 board/sunxi/Kconfig           |  3 ++
 drivers/usb/host/ehci-sunxi.c | 93 +++++++++++++++++++++++++++++--------------
 2 files changed, 67 insertions(+), 29 deletions(-)
Quoted 1 line

Applied to u-boot-dm, thanks!

Actually, not applied. Hans can you please rebase on u-boot-dm? I seem to get conflicts.

Regards,
Simon

#26 lore raw

PATCH v4 9/9 sunxi: ehci: Convert to the driver-model

Hi,

Quoted 17 lines · Simon Glass

Hi Hans,

Quoted 14 lines · Simon Glass
Quoted 12 lines · Hans de Goede

Convert sunxi-boards which use the sunxi-ehci code to the driver-model.

---
Changes in v4:
-Add a comment to document the setting of some priv-data members based on
the controller base-address

---
  board/sunxi/Kconfig           |  3 ++
  drivers/usb/host/ehci-sunxi.c | 93 +++++++++++++++++++++++++++++--------------
  2 files changed, 67 insertions(+), 29 deletions(-)
Quoted 4 lines
Quoted 1 line

Applied to u-boot-dm, thanks!

Actually, not applied. Hans can you please rebase on u-boot-dm? I seem to get conflicts.

Those are likely because Tom has not yet pulled my recent sunxi pull-req, I can take this one upstream myself through the sunxi tree once the other patches are merged.

I'm going afk for 3 days starting tomorrow, if you've the time please send a pull-req for the first 8 patches and I'll take care of this one once they are merged.

Thanks & Regards,

Hans

#27 lore raw

PATCH v4 9/9 sunxi: ehci: Convert to the driver-model

Hi Hans,

Quoted 34 lines · Hans de Goede

Hi,

Quoted 23 lines · Simon Glass

Hi Hans,

Quoted 19 lines · Simon Glass
Quoted 15 lines · Hans de Goede

Convert sunxi-boards which use the sunxi-ehci code to the driver-model.

---
Changes in v4:
-Add a comment to document the setting of some priv-data members based on
the controller base-address

---
  board/sunxi/Kconfig           |  3 ++
  drivers/usb/host/ehci-sunxi.c | 93
+++++++++++++++++++++++++++++--------------
  2 files changed, 67 insertions(+), 29 deletions(-)
Quoted 5 lines
Quoted 1 line

Applied to u-boot-dm, thanks!

Actually, not applied. Hans can you please rebase on u-boot-dm? I seem to get conflicts.

Quoted 7 lines

Those are likely because Tom has not yet pulled my recent sunxi pull-req, I can take this one upstream myself through the sunxi tree once the other patches are merged.

I'm going afk for 3 days starting tomorrow, if you've the time please send a pull-req for the first 8 patches and I'll take care of this one once they are merged.

OK. I've got to wait for the x86 pull request too. So let's see how things pan out.

Regards,
Simon

#14 lore raw

PATCH v4 6/9 dm: usb: Add support for interrupt queues to the dm usb code

In reply to Simon Glass

Hi Hans,

Quoted 10 lines · Simon Glass
Quoted 9 lines · Hans de Goede

Interrupt 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.

Quoted 8 lines
Quoted 6 lines
---
 drivers/usb/host/usb-uclass.c | 36 ++++++++++++++++++++++++++++++++
 include/usb.h                 | 48 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

Again I am getting ahead of myself. This one fails on some Samsung boards:

35: dm: usb: Add support for interrupt queues to the dm usb code
arm: + arndale odroid snow odroid-xu3
+drivers/usb/host/ehci-hcd.o: In function `create_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1258: multiple definition of `create_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:71:
first defined here
+drivers/usb/host/ehci-hcd.o: In function `poll_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1414: multiple definition of `poll_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:83:
first defined here
+drivers/usb/host/ehci-hcd.o: In function `destroy_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1450: multiple definition of `destroy_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:94:
first defined here
+make[2]: *** [drivers/usb/host/built-in.o] Error 1
+make[1]: *** [drivers/usb/host] Error 2

I'll drop this patch until you respin it.

Regards,
Simon

#19 lore raw

PATCH v4 7/9 dm: usb: Prefix ehci interrupt-queue functions with _ehci_

In reply to Simon Glass

Hi Hans,

Quoted 11 lines · Simon Glass
Quoted 8 lines · Hans de Goede

This 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(-)

Applied to u-boot-dm, thanks!

I've had to drop this because of the build error with patch 6/9.

Can you please respin against dm/master when you return?

Regards,
Simon

#22 lore raw

PATCH v4 8/9 dm: usb: Add support for interrupt queues to the dm ehci code

In reply to Simon Glass

Hi Hans,

Quoted 10 lines · Simon Glass
Quoted 7 lines · Hans de Goede

Add support for interrupt queues to the dm ehci code.

---
 drivers/usb/host/ehci-hcd.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Applied to u-boot-dm, thanks!

I've had to drop this because of the build error with patch 6/9.

Can you please respin against dm/master when you return?

Regards,
Simon

#15 lore raw

PATCH v4 6/9 dm: usb: Add support for interrupt queues to the dm usb code

In reply to Simon Glass

Hi,

Quoted 44 lines · Simon Glass

Hi Hans,

Quoted 10 lines · Simon Glass
Quoted 9 lines · Hans de Goede

Interrupt 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.

Quoted 8 lines
Quoted 6 lines
---
  drivers/usb/host/usb-uclass.c | 36 ++++++++++++++++++++++++++++++++
  include/usb.h                 | 48 ++++++++++++++++++++++++++++++++++++++++++-
  2 files changed, 83 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

Again I am getting ahead of myself. This one fails on some Samsung boards:

35: dm: usb: Add support for interrupt queues to the dm usb code
arm: + arndale odroid snow odroid-xu3

(quoted diff) +2 -0
+drivers/usb/host/ehci-hcd.o: In function `create_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1258: multiple definition of

`create_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:71:
first defined here

(quoted diff) +2 -0
+drivers/usb/host/ehci-hcd.o: In function `poll_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1414: multiple definition of

`poll_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:83:
first defined here

(quoted diff) +2 -0
+drivers/usb/host/ehci-hcd.o: In function `destroy_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1450: multiple definition of

`destroy_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:94:
first defined here

(quoted diff) +2 -0
+make[2]: *** [drivers/usb/host/built-in.o] Error 1
+make[1]: *** [drivers/usb/host] Error 2
Quoted 1 line

I'll drop this patch until you respin it.

Weird, in my tree, after this patch, the definition of create_int_queue
in ehci-hcd.c is in a "#ifndef CONFIG_DM_USB" block. So I think this maybe
an issue elsewhere. Maybe related to "[PATCH v2 79/80] dm: usb: exynos: Drop legacy USB code" which judging from your mail timestamps you did not have applied yet when seeing this build failure.

Anyways I see that you've already merged quite a bit of my patches, so I'll rebase on top of u-boot-dm/master, fix all the review comments and I'll also look into this one.

Regards,

Hans

#16 lore raw

PATCH v4 6/9 dm: usb: Add support for interrupt queues to the dm usb code

In reply to Simon Glass

Hi,

Quoted 44 lines · Simon Glass

Hi Hans,

Quoted 10 lines · Simon Glass
Quoted 9 lines · Hans de Goede

Interrupt 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.

Quoted 8 lines
Quoted 6 lines
---
  drivers/usb/host/usb-uclass.c | 36 ++++++++++++++++++++++++++++++++
  include/usb.h                 | 48 ++++++++++++++++++++++++++++++++++++++++++-
  2 files changed, 83 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

Again I am getting ahead of myself. This one fails on some Samsung boards:

35: dm: usb: Add support for interrupt queues to the dm usb code
arm: + arndale odroid snow odroid-xu3

(quoted diff) +2 -0
+drivers/usb/host/ehci-hcd.o: In function `create_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1258: multiple definition of

`create_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:71:
first defined here

(quoted diff) +2 -0
+drivers/usb/host/ehci-hcd.o: In function `poll_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1414: multiple definition of

`poll_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:83:
first defined here

(quoted diff) +2 -0
+drivers/usb/host/ehci-hcd.o: In function `destroy_int_queue':
+build/../drivers/usb/host/ehci-hcd.c:1450: multiple definition of

`destroy_int_queue' +drivers/usb/host/usb-uclass.o:build/../drivers/usb/host/usb-uclass.c:94:
first defined here

(quoted diff) +2 -0
+make[2]: *** [drivers/usb/host/built-in.o] Error 1
+make[1]: *** [drivers/usb/host] Error 2
Quoted 1 line

I'll drop this patch until you respin it.

Thinking more about this, now I understand what is going on, this build failure goes away with the patch titled:

"dm: usb: Add support for interrupt queues to the dm ehci code"

I understand that having a build failure halfway through the series is not acceptable, so I'll squash the 2 together.

Regards

Hans