Skip to contentSkip to conversation

usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

PATCH Superseded Igor Opaniuk 2 participants 6 messages Oct 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

From: Igor Opaniuk <[email protected]>

This fixes the issues with calculation of controller indexes in ehci_usb_bind() for iMX7, as USB controllers on iMX7 SoCs aren't placed next to each other, and their addresses incremented by 0x1000.

Example of USB nodes for iMX7S/D:

usbotg1: usb at 30b10000 {
    compatible = "fsl,imx7d-usb", "fsl,imx27-usb";
    reg = <0x30b10000 0x200>;
           ^^^^^^^^^^
....
usbotg2: usb at 30b20000 {
    compatible = "fsl,imx7d-usb", "fsl,imx27-usb";
    reg = <0x30b20000 0x200>;
           ^^^^^^^^^^

....

usbh: usb at 30b30000 {
    compatible = "fsl,imx7d-usb", "fsl,imx27-usb";
    reg = <0x30b30000 0x200>;
           ^^^^^^^^^^

....

Which was leading to usb enumeration issues:
Colibri iMX7 # usb start
starting USB...
Bus usb at 30b10000: USB EHCI 1.00
Bus usb at 30b20000: probe failed, error -22
scanning bus usb at 30b10000 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

Fixes 501547cec1("usb: ehci-mx6: Fix bus enumeration for DM case")

---

 drivers/usb/host/ehci-mx6.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/usb/host/ehci-mx6.c +12 -7
index e9e6ed596d..d60b36d7b5 100644
@@ -513,10 +513,11 @@ static int ehci_usb_bind(struct udevice *dev)
 	 * from which it derives offsets in the PHY and ANATOP register sets.
 	 *
 	 * Here we attempt to calculate these indexes from DT information as
-	 * well as we can. The USB controllers on all existing iMX6/iMX7 SoCs
-	 * are placed next to each other, at addresses incremented by 0x200.
-	 * Thus, the index is derived from the multiple of 0x200 offset from
-	 * the first controller address.
+	 * well as we can. The USB controllers on all existing iMX6 SoCs
+	 * are placed next to each other, at addresses incremented by 0x200,
+	 * and iMX7 their addresses are shifted by 0x1000.
+	 * Thus, the index is derived from the multiple of 0x200 (0x1000 for
+	 * iMX7) offset from the first controller address.
 	 *
 	 * However, to complete conversion of this driver to DT probing, the
 	 * following has to be done:
@@ -531,10 +532,14 @@ static int ehci_usb_bind(struct udevice *dev)
 	 * With these changes in place, the ad-hoc indexing goes away and
 	 * the driver is fully converted to DT probing.
 	 */
-	fdt_size_t size;
-	fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, &size);
+#if defined(CONFIG_MX6)
+	u32 controller_spacing = 0x200;
+#elif defined(CONFIG_MX7)
+	u32 controller_spacing = 0x10000;
+#endif
+	fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, NULL);
 
-	dev->req_seq = (addr - USB_BASE_ADDR) / size;
+	dev->req_seq = (addr - USB_BASE_ADDR) / controller_spacing;
 
 	return 0;
 }
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

On 10/10/19 1:25 PM, Igor Opaniuk wrote:
[...]

Quoted 17 lines
drivers/usb/host/ehci-mx6.c +5 -4
 	 * from which it derives offsets in the PHY and ANATOP register sets.
 	 *
 	 * Here we attempt to calculate these indexes from DT information as
-	 * well as we can. The USB controllers on all existing iMX6/iMX7 SoCs
-	 * are placed next to each other, at addresses incremented by 0x200.
-	 * Thus, the index is derived from the multiple of 0x200 offset from
-	 * the first controller address.
+	 * well as we can. The USB controllers on all existing iMX6 SoCs
+	 * are placed next to each other, at addresses incremented by 0x200,
+	 * and iMX7 their addresses are shifted by 0x1000.
+	 * Thus, the index is derived from the multiple of 0x200 (0x1000 for
+	 * iMX7) offset from the first controller address.
 	 *
 	 * However, to complete conversion of this driver to DT probing, the
 	 * following has to be done:
@@ -531,10 +532,14 @@ static int ehci_usb_bind(struct udevice *dev)
 	 * With these changes in place, the ad-hoc indexing goes away and

drivers/usb/host/ehci-mx6.c static int ehci_usb_bind(struct udevice *dev) · line 540

Quoted 10 lines
drivers/usb/host/ehci-mx6.c +6 -2
 	 * the driver is fully converted to DT probing.
 	 */
-	fdt_size_t size;
-	fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, &size);
+#if defined(CONFIG_MX6)
+	u32 controller_spacing = 0x200;
+#elif defined(CONFIG_MX7)
+	u32 controller_spacing = 0x10000;
+#endif
+	fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, NULL);

This won't work with U-Boot that's compiled for both platforms, so you need some other way to discern those two things. Either something like cpu_is_...() or some DT match.

#2 lore raw

PATCH 1/1 usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

Hi Marek

Quoted 26 lines · Marek Vasut

On 10/10/19 1:25 PM, Igor Opaniuk wrote:
[...]

Quoted 23 lines

* from which it derives offsets in the PHY and ANATOP register sets. *
* Here we attempt to calculate these indexes from DT information as

drivers/usb/host/ehci-mx6.c +7 -6
-      * well as we can. The USB controllers on all existing iMX6/iMX7 SoCs
-      * are placed next to each other, at addresses incremented by 0x200.
-      * Thus, the index is derived from the multiple of 0x200 offset from
-      * the first controller address.
+      * well as we can. The USB controllers on all existing iMX6 SoCs
+      * are placed next to each other, at addresses incremented by 0x200,
+      * and iMX7 their addresses are shifted by 0x1000.
+      * Thus, the index is derived from the multiple of 0x200 (0x1000 for
+      * iMX7) offset from the first controller address.
       *
       * However, to complete conversion of this driver to DT probing, the
       * following has to be done:
@@ -531,10 +532,14 @@ static int ehci_usb_bind(struct udevice *dev)
       * With these changes in place, the ad-hoc indexing goes away and
       * the driver is fully converted to DT probing.
       */
-     fdt_size_t size;
-     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, &size);
+#if defined(CONFIG_MX6)
+     u32 controller_spacing = 0x200;
Quoted 8 lines

drivers/usb/host/ehci-mx6.c static int ehci_usb_bind(struct udevice *dev) · line 540

Quoted 4 lines
drivers/usb/host/ehci-mx6.c +4 -0
+#elif defined(CONFIG_MX7)
+     u32 controller_spacing = 0x10000;
+#endif
+     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, NULL);

This won't work with U-Boot that's compiled for both platforms, so you need some other way to discern those two things. Either something like cpu_is_...() or some DT match.

So in that case existing ehci_hcd_init() implementation
won't work either, as it does the same.
So if we want to address this case (anyway, is it the real case when both CONFIG_MX6 and CONFIG_MX7 are defined?), we will have to reimplement other parts of the driver.

But taking into account that it's a temporary workaround and should be fully reimplemented,why not to proceed with a pretty simple solution for now as what is done in ehci-vf.c :

295 static int vf_usb_bind(struct udevice *dev)
296 {
297 static int num_controllers;
298
299 /*
300 * Without this hack, if we return ENODEV for USB
Controller 0, on
301 * probe for the next controller, USB Controller 1 will be
given a
302 * sequence number of 0. This conflicts with our
requirement of
303 * sequence numbers while initialising the peripherals.
304 */
305 dev->req_seq = num_controllers;
306 num_controllers++;
307
308 return 0;
309 }

Thanks

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#3 lore raw

PATCH 1/1 usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

Quoted 1 line · Igor Opaniuk

Hi Marek

Hi Igor,

Quoted 36 lines · Marek Vasut
Quoted 26 lines · Igor Opaniuk

[...]

Quoted 23 lines

* from which it derives offsets in the PHY and ANATOP register sets. *
* Here we attempt to calculate these indexes from DT information as

drivers/usb/host/ehci-mx6.c +7 -6
-      * well as we can. The USB controllers on all existing iMX6/iMX7 SoCs
-      * are placed next to each other, at addresses incremented by 0x200.
-      * Thus, the index is derived from the multiple of 0x200 offset from
-      * the first controller address.
+      * well as we can. The USB controllers on all existing iMX6 SoCs
+      * are placed next to each other, at addresses incremented by 0x200,
+      * and iMX7 their addresses are shifted by 0x1000.
+      * Thus, the index is derived from the multiple of 0x200 (0x1000 for
+      * iMX7) offset from the first controller address.
       *
       * However, to complete conversion of this driver to DT probing, the
       * following has to be done:
@@ -531,10 +532,14 @@ static int ehci_usb_bind(struct udevice *dev)
       * With these changes in place, the ad-hoc indexing goes away and
       * the driver is fully converted to DT probing.
       */
-     fdt_size_t size;
-     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, &size);
+#if defined(CONFIG_MX6)
+     u32 controller_spacing = 0x200;
Quoted 8 lines

drivers/usb/host/ehci-mx6.c static int ehci_usb_bind(struct udevice *dev) · line 540

Quoted 4 lines
drivers/usb/host/ehci-mx6.c +4 -0
+#elif defined(CONFIG_MX7)
+     u32 controller_spacing = 0x10000;
+#endif
+     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, NULL);

This won't work with U-Boot that's compiled for both platforms, so you need some other way to discern those two things. Either something like cpu_is_...() or some DT match.

Quoted 2 lines

So in that case existing ehci_hcd_init() implementation won't work either, as it does the same.

Only the non-DM_USB one though , right ? The ehci_usb_bind() is a DM code and probes from information in DT (or platdata), hence no such ifdeffery is allowed.

Quoted 7 lines

So if we want to address this case (anyway, is it the real case when both CONFIG_MX6 and CONFIG_MX7 are defined?), we will have to reimplement other parts of the driver.

But taking into account that it's a temporary workaround and should be fully reimplemented,why not to proceed with a pretty simple solution for now as what is done in ehci-vf.c :

Because this does not work if ehci0 is not your first controller, then the derivation of ANATOP bit offsets breaks down because the controller indexes are off. That's what the original patch was trying to fix and what is described in that long explanation text in the driver too. I was trying to make sure this problem is documented.

I think ehci-vf and ehci-mx5 have the same problem and need to be fixed too. But the real fix is to finish converting the driver to DM proper and fix that ANATOP bit offset derivation properly. Or even pull it out of DT, which would be the best.

Anyway, what about this:

u32 controller_spacing = is_mx7() ? 0x1000 : 0x200; fdt_addr_t addr = devfdt_get_addr_index(dev, 0);

This gets rid of the ifdeffery and works on both mx6 and mx7, no ?

Quoted 21 lines

295 static int vf_usb_bind(struct udevice *dev)
296 {
297 static int num_controllers;
298
299 /*
300 * Without this hack, if we return ENODEV for USB
Controller 0, on
301 * probe for the next controller, USB Controller 1 will be
given a
302 * sequence number of 0. This conflicts with our
requirement of
303 * sequence numbers while initialising the peripherals.
304 */
305 dev->req_seq = num_controllers;
306 num_controllers++;
307
308 return 0;
309 }

Thanks

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

PATCH 1/1 usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

Quoted 63 lines · Marek Vasut
Quoted 1 line · Igor Opaniuk

Hi Marek

Hi Igor,

Quoted 36 lines · Marek Vasut
Quoted 26 lines · Igor Opaniuk

[...]

Quoted 23 lines

* from which it derives offsets in the PHY and ANATOP register sets. *
* Here we attempt to calculate these indexes from DT information as

drivers/usb/host/ehci-mx6.c +7 -6
-      * well as we can. The USB controllers on all existing iMX6/iMX7 SoCs
-      * are placed next to each other, at addresses incremented by 0x200.
-      * Thus, the index is derived from the multiple of 0x200 offset from
-      * the first controller address.
+      * well as we can. The USB controllers on all existing iMX6 SoCs
+      * are placed next to each other, at addresses incremented by 0x200,
+      * and iMX7 their addresses are shifted by 0x1000.
+      * Thus, the index is derived from the multiple of 0x200 (0x1000 for
+      * iMX7) offset from the first controller address.
       *
       * However, to complete conversion of this driver to DT probing, the
       * following has to be done:
@@ -531,10 +532,14 @@ static int ehci_usb_bind(struct udevice *dev)
       * With these changes in place, the ad-hoc indexing goes away and
       * the driver is fully converted to DT probing.
       */
-     fdt_size_t size;
-     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, &size);
+#if defined(CONFIG_MX6)
+     u32 controller_spacing = 0x200;
Quoted 8 lines

drivers/usb/host/ehci-mx6.c static int ehci_usb_bind(struct udevice *dev) · line 540

Quoted 4 lines
drivers/usb/host/ehci-mx6.c +4 -0
+#elif defined(CONFIG_MX7)
+     u32 controller_spacing = 0x10000;
+#endif
+     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, NULL);

This won't work with U-Boot that's compiled for both platforms, so you need some other way to discern those two things. Either something like cpu_is_...() or some DT match.

Quoted 2 lines

So in that case existing ehci_hcd_init() implementation won't work either, as it does the same.

Only the non-DM_USB one though , right ? The ehci_usb_bind() is a DM code and probes from information in DT (or platdata), hence no such ifdeffery is allowed.

Quoted 7 lines

So if we want to address this case (anyway, is it the real case when both CONFIG_MX6 and CONFIG_MX7 are defined?), we will have to reimplement other parts of the driver.

But taking into account that it's a temporary workaround and should be fully reimplemented,why not to proceed with a pretty simple solution for now as what is done in ehci-vf.c :

Because this does not work if ehci0 is not your first controller, then the derivation of ANATOP bit offsets breaks down because the controller indexes are off. That's what the original patch was trying to fix and what is described in that long explanation text in the driver too. I was trying to make sure this problem is documented.

Quoted 4 lines

I think ehci-vf and ehci-mx5 have the same problem and need to be fixed too. But the real fix is to finish converting the driver to DM proper and fix that ANATOP bit offset derivation properly. Or even pull it out of DT, which would be the best.

Thanks for the explanation!

Quoted 7 lines

Anyway, what about this:

u32 controller_spacing = is_mx7() ? 0x1000 : 0x200; fdt_addr_t addr = devfdt_get_addr_index(dev, 0);

This gets rid of the ifdeffery and works on both mx6 and mx7, no ?

Makes sense, will change it in v2.

Quoted 20 lines
Quoted 20 lines

295 static int vf_usb_bind(struct udevice *dev)
296 {
297 static int num_controllers;
298
299 /*
300 * Without this hack, if we return ENODEV for USB
Controller 0, on
301 * probe for the next controller, USB Controller 1 will be
given a
302 * sequence number of 0. This conflicts with our
requirement of
303 * sequence numbers while initialising the peripherals.
304 */
305 dev->req_seq = num_controllers;
306 num_controllers++;
307
308 return 0;
309 }

Quoted 7 lines
Quoted 2 lines

Thanks

--
Best regards,
Marek Vasut

Thanks

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#5 lore raw

PATCH 1/1 usb: ehci-mx6: Fix bus enumeration for iMX7 SoCs

Quoted 71 lines · Igor Opaniuk
Quoted 63 lines · Marek Vasut
Quoted 1 line · Igor Opaniuk

Hi Marek

Hi Igor,

Quoted 36 lines · Marek Vasut
Quoted 26 lines · Igor Opaniuk

[...]

Quoted 23 lines

* from which it derives offsets in the PHY and ANATOP register sets. *
* Here we attempt to calculate these indexes from DT information as

drivers/usb/host/ehci-mx6.c +7 -6
-      * well as we can. The USB controllers on all existing iMX6/iMX7 SoCs
-      * are placed next to each other, at addresses incremented by 0x200.
-      * Thus, the index is derived from the multiple of 0x200 offset from
-      * the first controller address.
+      * well as we can. The USB controllers on all existing iMX6 SoCs
+      * are placed next to each other, at addresses incremented by 0x200,
+      * and iMX7 their addresses are shifted by 0x1000.
+      * Thus, the index is derived from the multiple of 0x200 (0x1000 for
+      * iMX7) offset from the first controller address.
       *
       * However, to complete conversion of this driver to DT probing, the
       * following has to be done:
@@ -531,10 +532,14 @@ static int ehci_usb_bind(struct udevice *dev)
       * With these changes in place, the ad-hoc indexing goes away and
       * the driver is fully converted to DT probing.
       */
-     fdt_size_t size;
-     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, &size);
+#if defined(CONFIG_MX6)
+     u32 controller_spacing = 0x200;
Quoted 8 lines

drivers/usb/host/ehci-mx6.c static int ehci_usb_bind(struct udevice *dev) · line 540

Quoted 4 lines
drivers/usb/host/ehci-mx6.c +4 -0
+#elif defined(CONFIG_MX7)
+     u32 controller_spacing = 0x10000;
+#endif
+     fdt_addr_t addr = devfdt_get_addr_size_index(dev, 0, NULL);

This won't work with U-Boot that's compiled for both platforms, so you need some other way to discern those two things. Either something like cpu_is_...() or some DT match.

Quoted 2 lines

So in that case existing ehci_hcd_init() implementation won't work either, as it does the same.

Only the non-DM_USB one though , right ? The ehci_usb_bind() is a DM code and probes from information in DT (or platdata), hence no such ifdeffery is allowed.

Quoted 7 lines

So if we want to address this case (anyway, is it the real case when both CONFIG_MX6 and CONFIG_MX7 are defined?), we will have to reimplement other parts of the driver.

But taking into account that it's a temporary workaround and should be fully reimplemented,why not to proceed with a pretty simple solution for now as what is done in ehci-vf.c :

Because this does not work if ehci0 is not your first controller, then the derivation of ANATOP bit offsets breaks down because the controller indexes are off. That's what the original patch was trying to fix and what is described in that long explanation text in the driver too. I was trying to make sure this problem is documented.

Quoted 4 lines

I think ehci-vf and ehci-mx5 have the same problem and need to be fixed too. But the real fix is to finish converting the driver to DM proper and fix that ANATOP bit offset derivation properly. Or even pull it out of DT, which would be the best.

Thanks for the explanation!

Quoted 1 line
Quoted 7 lines
Quoted 6 lines

Anyway, what about this:

u32 controller_spacing = is_mx7() ? 0x1000 : 0x200; fdt_addr_t addr = devfdt_get_addr_index(dev, 0);

This gets rid of the ifdeffery and works on both mx6 and mx7, no ?

Makes sense, will change it in v2.

Great, thanks!