Skip to contentSkip to conversation

dm: usb: setup ehci gadget before usb is probed

PATCH New Ramon Fried 2 participants 4 messages May 21, 2018 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: usb: setup ehci gadget before usb is probed

usb_setup_ehci_gadget() looks for a loaded USB class driver, then it unloads it and loads it again as a device instead of host. This change loads the USB class driver as device if it wasn't loaded in the first place.

---
 drivers/usb/host/usb-uclass.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/usb/host/usb-uclass.c +10 -5
index 611ea97a72..7ab7e8990c 100644
@@ -380,17 +380,22 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 
 int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp)
 {
+	TRACE();
 	struct usb_platdata *plat;
 	struct udevice *dev;
 	int ret;
 
 	/* Find the old device and remove it */
 	ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
-	if (ret)
-		return ret;
-	ret = device_remove(dev, DM_REMOVE_NORMAL);
-	if (ret)
-		return ret;
+	if (ret) {
+		ret = uclass_find_device(UCLASS_USB, 0, &dev);
+		if (ret)
+			return ret;
+	} else {
+		ret = device_remove(dev, DM_REMOVE_NORMAL);
+		if (ret)
+			return ret;
+	}
 
 	plat = dev_get_platdata(dev);
 	plat->init_type = USB_INIT_DEVICE;
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/1 dm: usb: setup ehci gadget before usb is probed

Quoted 4 lines · Ramon Fried

usb_setup_ehci_gadget() looks for a loaded USB class driver, then it unloads it and loads it again as a device instead of host. This change loads the USB class driver as device if it wasn't loaded in the first place.

To achieve what ? What is the purpose of this patch ? Are you fixing a bug or improving the code or what ?

Quoted 38 lines
---
 drivers/usb/host/usb-uclass.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/usb/host/usb-uclass.c +10 -5
index 611ea97a72..7ab7e8990c 100644
@@ -380,17 +380,22 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 
 int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp)
 {
+	TRACE();
 	struct usb_platdata *plat;
 	struct udevice *dev;
 	int ret;
 
 	/* Find the old device and remove it */
 	ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
-	if (ret)
-		return ret;
-	ret = device_remove(dev, DM_REMOVE_NORMAL);
-	if (ret)
-		return ret;
+	if (ret) {
+		ret = uclass_find_device(UCLASS_USB, 0, &dev);
+		if (ret)
+			return ret;
+	} else {
+		ret = device_remove(dev, DM_REMOVE_NORMAL);
+		if (ret)
+			return ret;
+	}
 
 	plat = dev_get_platdata(dev);
 	plat->init_type = USB_INIT_DEVICE;
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 dm: usb: setup ehci gadget before usb is probed

Quoted 8 lines · Marek Vasut
Quoted 4 lines · Ramon Fried

usb_setup_ehci_gadget() looks for a loaded USB class driver, then it unloads it and loads it again as a device instead of host. This change loads the USB class driver as device if it wasn't loaded in the first place.

To achieve what ? What is the purpose of this patch ? Are you fixing a bug or improving the code or what ?

This is an improvement of the code.

If I want for instance to run fastboot. running fastboot will fail if "start usb" wasn't
run before.

In this scenario, "start usb" will start the USB as host, scan & enumerate the bus only
to be taken down and brought up again as a device when usb_setup_ehci_gadget() is called.

Hope it's much clearer now.
Thanks,
Ramon.

Quoted 44 lines
Quoted 29 lines
---
 drivers/usb/host/usb-uclass.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/usb/host/usb-uclass.c +3 -5
index 611ea97a72..7ab7e8990c 100644
@@ -380,17 +380,22 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 
 int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp)
 {
+     TRACE();
      struct usb_platdata *plat;
      struct udevice *dev;
      int ret;
 
      /* Find the old device and remove it */
      ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
-     if (ret)
-             return ret;
-     ret = device_remove(dev, DM_REMOVE_NORMAL);
-     if (ret)
-             return ret;
+     if (ret) {
+             ret = uclass_find_device(UCLASS_USB, 0, &dev);

drivers/usb/host/usb-uclass.c struct usb_device *usb_get_dev_index(struct udevice *bus, int index) · line 401

Quoted 10 lines
drivers/usb/host/usb-uclass.c +7 -0
+             if (ret)
+                     return ret;
+     } else {
+             ret = device_remove(dev, DM_REMOVE_NORMAL);
+             if (ret)
+                     return ret;
+     }
 
      plat = dev_get_platdata(dev);
      plat->init_type = USB_INIT_DEVICE;

--
Best regards,
Marek Vasut

#3 lore raw

PATCH 1/1 dm: usb: setup ehci gadget before usb is probed

Quoted 15 lines · Ramon Fried
Quoted 8 lines · Marek Vasut
Quoted 4 lines · Ramon Fried

usb_setup_ehci_gadget() looks for a loaded USB class driver, then it unloads it and loads it again as a device instead of host. This change loads the USB class driver as device if it wasn't loaded in the first place.

To achieve what ? What is the purpose of this patch ? Are you fixing a bug or improving the code or what ?

This is an improvement of the code.

If I want for instance to run fastboot. running fastboot will fail if "start usb" wasn't
run before.

Quoted 6 lines

In this scenario, "start usb" will start the USB as host, scan & enumerate the bus only
to be taken down and brought up again as a device when usb_setup_ehci_gadget() is called.

Hope it's much clearer now.

CCing Lukasz to look at this.

Quoted 47 lines

Thanks,
Ramon.

Quoted 44 lines
Quoted 29 lines
---
 drivers/usb/host/usb-uclass.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/usb/host/usb-uclass.c +3 -5
index 611ea97a72..7ab7e8990c 100644
@@ -380,17 +380,22 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 
 int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp)
 {
+     TRACE();
      struct usb_platdata *plat;
      struct udevice *dev;
      int ret;
 
      /* Find the old device and remove it */
      ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
-     if (ret)
-             return ret;
-     ret = device_remove(dev, DM_REMOVE_NORMAL);
-     if (ret)
-             return ret;
+     if (ret) {
+             ret = uclass_find_device(UCLASS_USB, 0, &dev);

drivers/usb/host/usb-uclass.c struct usb_device *usb_get_dev_index(struct udevice *bus, int index) · line 401

Quoted 10 lines
drivers/usb/host/usb-uclass.c +7 -0
+             if (ret)
+                     return ret;
+     } else {
+             ret = device_remove(dev, DM_REMOVE_NORMAL);
+             if (ret)
+                     return ret;
+     }
 
      plat = dev_get_platdata(dev);
      plat->init_type = USB_INIT_DEVICE;

--
Best regards,
Marek Vasut

Signature · 2 lines
Best regards,
Marek Vasut