Skip to contentSkip to conversation

ARM: socfpga: gen5: release reset before using USB as device with ums

PATCH Wolfgang Grandegger 2 participants 6 messages Feb 28, 2022 – Mar 14, 2022

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

The command "ums 0 mmc 0" does not work because the USB port is still in reset. Releasing it in board_usb_init() fixes the problem. This issue has been observed and fixed on the Aries MCVEVP board.

---
 arch/arm/dts/socfpga_cyclone5_mcvevk.dts                | 1 +
 arch/arm/mach-socfpga/board.c                           | 8 ++++++++
 arch/arm/mach-socfpga/include/mach/reset_manager_gen5.h | 2 ++
 3 files changed, 11 insertions(+)
arch/arm/dts/socfpga_cyclone5_mcvevk.dts +1 -0
index ceaec29770..a673837f25 100644
@@ -12,6 +12,7 @@
 	aliases {
 		ethernet0 = &gmac0;
 		stmpe-i2c0 = &stmpe1;
+		udc0 = &usb1;
 	};
 
 	chosen {
arch/arm/mach-socfpga/board.c +8 -0
index 7267163222..a2eed73fe9 100644
@@ -83,6 +83,14 @@ int board_usb_init(int index, enum usb_init_type init)
 	/* Patch the address from OF into the controller pdata. */
 	socfpga_otg_data.regs_otg = addr;
 
+#ifdef CONFIG_TARGET_SOCFPGA_GEN5
+	/* First release reset of the USB port */
+	if (addr == SOCFPGA_USB0_ADDRESS)
+		socfpga_per_reset(SOCFPGA_RESET(USB0), 0);
+	else if (addr == SOCFPGA_USB1_ADDRESS)
+		socfpga_per_reset(SOCFPGA_RESET(USB1), 0);
+#endif
+
 	return dwc2_udc_probe(&socfpga_otg_data);
 }
 
arch/arm/mach-socfpga/include/mach/reset_manager_gen5.h +2 -0
index d108eac1e2..611403cf00 100644
@@ -31,6 +31,8 @@ void socfpga_bridges_reset(int enable);
  */
 #define RSTMGR_EMAC0		RSTMGR_DEFINE(1, 0)
 #define RSTMGR_EMAC1		RSTMGR_DEFINE(1, 1)
+#define RSTMGR_USB0		RSTMGR_DEFINE(1, 2)
+#define RSTMGR_USB1		RSTMGR_DEFINE(1, 3)
 #define RSTMGR_NAND		RSTMGR_DEFINE(1, 4)
 #define RSTMGR_QSPI		RSTMGR_DEFINE(1, 5)
 #define RSTMGR_L4WD0		RSTMGR_DEFINE(1, 6)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 28 lines · Wolfgang Grandegger

The command "ums 0 mmc 0" does not work because the USB port is still in reset. Releasing it in board_usb_init() fixes the problem. This issue has been observed and fixed on the Aries MCVEVP board.

---
  arch/arm/dts/socfpga_cyclone5_mcvevk.dts                | 1 +
  arch/arm/mach-socfpga/board.c                           | 8 ++++++++
  arch/arm/mach-socfpga/include/mach/reset_manager_gen5.h | 2 ++
  3 files changed, 11 insertions(+)
arch/arm/dts/socfpga_cyclone5_mcvevk.dts +1 -0
index ceaec29770..a673837f25 100644
@@ -12,6 +12,7 @@
  	aliases {
  		ethernet0 = &gmac0;
  		stmpe-i2c0 = &stmpe1;
+		udc0 = &usb1;
  	};
 
  	chosen {
arch/arm/mach-socfpga/board.c +0 -0
index 7267163222..a2eed73fe9 100644

arch/arm/mach-socfpga/board.c int board_usb_init(int index, enum usb_init_type init) · line 92

Quoted 10 lines
arch/arm/mach-socfpga/board.c +7 -0
@@ -83,6 +83,14 @@ int board_usb_init(int index, enum usb_init_type init)
  	/* Patch the address from OF into the controller pdata. */
  	socfpga_otg_data.regs_otg = addr;
 
+#ifdef CONFIG_TARGET_SOCFPGA_GEN5
+	/* First release reset of the USB port */
+	if (addr == SOCFPGA_USB0_ADDRESS)
+		socfpga_per_reset(SOCFPGA_RESET(USB0), 0);
+	else if (addr == SOCFPGA_USB1_ADDRESS)
+		socfpga_per_reset(SOCFPGA_RESET(USB1), 0);
+#endif

Is this really needed at all ?

There is drivers/reset/reset-socfpga.c which should handle the reset of the DWC2 USB IP.

#2 lore raw

Hello Marek,

Am 28.02.22 um 15:51 schrieb Marek Vasut:

Quoted 33 lines · Wolfgang Grandegger
Quoted 32 lines

The command "ums 0 mmc 0" does not work because the USB port is still in reset. Releasing it in board_usb_init() fixes the problem. This issue has been observed and fixed on the Aries MCVEVP board.

---
  arch/arm/dts/socfpga_cyclone5_mcvevk.dts                | 1 + arch/arm/mach-socfpga/board.c                           | 8 ++++++++ arch/arm/mach-socfpga/include/mach/reset_manager_gen5.h | 2 ++

  3 files changed, 11 insertions(+)
arch/arm/dts/socfpga_cyclone5_mcvevk.dts +1 -0
index ceaec29770..a673837f25 100644
@@ -12,6 +12,7 @@
       aliases {
           ethernet0 = &gmac0;
           stmpe-i2c0 = &stmpe1;
+        udc0 = &usb1;
       };
         chosen {
arch/arm/mach-socfpga/board.c +0 -0
index 7267163222..a2eed73fe9 100644
@@ -83,6 +83,14 @@ int board_usb_init(int index, enum usb_init_type init)
       /* Patch the address from OF into the controller pdata. */
       socfpga_otg_data.regs_otg = addr;

  +#ifdef CONFIG_TARGET_SOCFPGA_GEN5

Quoted 8 lines
Quoted 6 lines

+    /* First release reset of the USB port */ +    if (addr == SOCFPGA_USB0_ADDRESS)
+        socfpga_per_reset(SOCFPGA_RESET(USB0), 0); +    else if (addr == SOCFPGA_USB1_ADDRESS) +        socfpga_per_reset(SOCFPGA_RESET(USB1), 0); +#endif

Is this really needed at all ?

Yes, it's needed, otherwise "ums 0 mmc 0" does not work. It was working some time ago but commit 430b42f76a4e50ffef7cc2b3c195ff645a438433 did remove the ad-hoc reset code. I realize the issue an on Aries MCVEVP board, but I'm quite sure that it's present on all Cyclone5 boards.

Quoted 2 lines

There is drivers/reset/reset-socfpga.c which should handle the reset of the DWC2 USB IP.

See above!

Wolfgang

#3 lore raw

On 2/28/22 16:18, Wolfgang Grandegger wrote:

Hi,

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
arch/arm/mach-socfpga/board.c +0 -0
index 7267163222..a2eed73fe9 100644
@@ -83,6 +83,14 @@ int board_usb_init(int index, enum usb_init_type init)
       /* Patch the address from OF into the controller pdata. */
       socfpga_otg_data.regs_otg = addr;
   +#ifdef CONFIG_TARGET_SOCFPGA_GEN5
Quoted 8 lines

arch/arm/mach-socfpga/board.c int board_usb_init(int index, enum usb_init_type init) · line 92

Quoted 6 lines
arch/arm/mach-socfpga/board.c +6 -0
+    /* First release reset of the USB port */
+    if (addr == SOCFPGA_USB0_ADDRESS)
+        socfpga_per_reset(SOCFPGA_RESET(USB0), 0);
+    else if (addr == SOCFPGA_USB1_ADDRESS)
+        socfpga_per_reset(SOCFPGA_RESET(USB1), 0);
+#endif

Is this really needed at all ?

Quoted 4 lines

Yes, it's needed, otherwise "ums 0 mmc 0" does not work. It was working some time ago but commit 430b42f76a4e50ffef7cc2b3c195ff645a438433 did remove the ad-hoc reset code. I realize the issue an on Aries MCVEVP board, but I'm quite sure that it's present on all Cyclone5 boards.

Can you investigate why the reset-socfpga.c does not release the USB from reset instead ? That would be the right approach.

#4 lore raw

Hello,

Am 28.02.22 um 16:22 schrieb Marek Vasut:

Quoted 25 lines · Wolfgang Grandegger

Hi,

[...]

Quoted 19 lines
Quoted 18 lines
Quoted 9 lines
arch/arm/mach-socfpga/board.c +0 -0
index 7267163222..a2eed73fe9 100644
@@ -83,6 +83,14 @@ int board_usb_init(int index, enum usb_init_type
 init)
        /* Patch the address from OF into the controller pdata. */
        socfpga_otg_data.regs_otg = addr;
Quoted 7 lines

   +#ifdef CONFIG_TARGET_SOCFPGA_GEN5
+    /* First release reset of the USB port */ +    if (addr == SOCFPGA_USB0_ADDRESS)
+        socfpga_per_reset(SOCFPGA_RESET(USB0), 0); +    else if (addr == SOCFPGA_USB1_ADDRESS) +        socfpga_per_reset(SOCFPGA_RESET(USB1), 0); +#endif

Is this really needed at all ?

Quoted 7 lines
Quoted 4 lines

Yes, it's needed, otherwise "ums 0 mmc 0" does not work. It was working some time ago but commit 430b42f76a4e50ffef7cc2b3c195ff645a438433 did remove the ad-hoc reset code. I realize the issue an on Aries MCVEVP board, but I'm quite sure that it's present on all Cyclone5 boards.

Can you investigate why the reset-socfpga.c does not release the USB from reset instead ? That would be the right approach.

The attached patch works. It enables CONFIG_DM_USB_GADGET and adds "dr_mode = otg" to the USB device tree node. "ums 0 mmc 0" deasserts the reset for USB1 and re-assert it when done. All ok with that!

But then "usb start" is broken:

=> usb start
starting USB...
USB: drv id 110 name usb
USB: drv id 90 name serial
USB: drv id 101 name sysreset
USB: drv id 85 name reset
USB: drv id 22 name blk
USB: drv id 59 name mmc
USB: drv id 99 name syscon
USB: drv id 25 name cache
USB: drv id 43 name i2c
USB: drv id 40 name gpio
USB: drv id 36 name ethernet
USB: drv id 91 name simple_bus
USB: drv id 0 name root
No working controllers found

The function "uclass_find()" does no longer find the USB host device (UCLASS_USB). The debug ouput is with:

drivers/core/uclass.c +3 -0
index 2578803b7a..b59a5dcdad 100644
@@ -35,6 +35,9 @@ struct uclass *uclass_find(enum uclass_id key)
         * id to node.
         */
        list_for_each_entry(uc, gd->uclass_root, sibling_node) {
+               if (key == UCLASS_USB)
+                       printf("USB: drv id %d name %s\n", 
+                              uc->uc_drv->id, uc->uc_drv->name);
                if (uc->uc_drv->id == key)
                        return uc;
        }

Id 110 is UCLASS_USB_GADGET_GENERIC, but UCLASS_USB is gone. There is some magic with usb device scanning. Any idea what could cause that problem?

Wolfgang

From 0d87f516fccf6fa00b77361e05382e585e99aa2c Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Fri, 11 Mar 2022 21:46:38 +0100
Subject: [PATCH 2/2] socfpga: mcvevk: fix reset handling to "make ums 0 mmc"
work

The command "ums 0 mmc 0" does not work, because the reset for the device is not deasserted. To fix it, we now use CONFIG_DM_USB_GADGET=y and add "dr_mode" to the usb device tree node.

---
 arch/arm/dts/socfpga_cyclone5_mcvevk.dts | 1 +
 configs/socfpga_mcvevk_defconfig         | 1 +
 2 files changed, 2 insertions(+)
arch/arm/dts/socfpga_cyclone5_mcvevk.dts +1 -0
index a673837f25..0c5a8ed1b5 100644
@@ -79,4 +79,5 @@
 
 &usb1 {
 	status = "okay";
+	dr_mode = "otg";
 };
configs/socfpga_mcvevk_defconfig +1 -0
index d31c3f5e77..369ef2d386 100644
@@ -54,6 +54,7 @@ CONFIG_SPI=y
 CONFIG_CADENCE_QSPI=y
 CONFIG_DESIGNWARE_SPI=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_DWC2=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_MANUFACTURER="denx"
Signature · 1 line
2.28.0
#5 lore raw
Quoted 78 lines · Wolfgang Grandegger

Hello,

Am 28.02.22 um 16:22 schrieb Marek Vasut:

Quoted 25 lines · Wolfgang Grandegger

Hi,

[...]

Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
arch/arm/mach-socfpga/board.c +0 -0
index 7267163222..a2eed73fe9 100644

arch/arm/mach-socfpga/board.c int board_usb_init(int index, enum usb_init_type · line 92

Quoted 10 lines
arch/arm/mach-socfpga/board.c +6 -0
@@ -83,6 +83,14 @@ int board_usb_init(int index, enum usb_init_type
 init)
        /* Patch the address from OF into the controller pdata. */
        socfpga_otg_data.regs_otg = addr;
    +#ifdef CONFIG_TARGET_SOCFPGA_GEN5
+    /* First release reset of the USB port */
+    if (addr == SOCFPGA_USB0_ADDRESS)
+        socfpga_per_reset(SOCFPGA_RESET(USB0), 0);
+    else if (addr == SOCFPGA_USB1_ADDRESS)
+        socfpga_per_reset(SOCFPGA_RESET(USB1), 0);
+#endif

Is this really needed at all ?

Quoted 7 lines
Quoted 4 lines

Yes, it's needed, otherwise "ums 0 mmc 0" does not work. It was working some time ago but commit 430b42f76a4e50ffef7cc2b3c195ff645a438433 did remove the ad-hoc reset code. I realize the issue an on Aries MCVEVP board, but I'm quite sure that it's present on all Cyclone5 boards.

Can you investigate why the reset-socfpga.c does not release the USB from reset instead ? That would be the right approach.

The attached patch works. It enables CONFIG_DM_USB_GADGET and adds "dr_mode = otg" to the USB device tree node. "ums 0 mmc 0" deasserts the reset for USB1 and re-assert it when done. All ok with that!

But then "usb start" is broken:

=> usb start
starting USB...
USB: drv id 110 name usb
USB: drv id 90 name serial
USB: drv id 101 name sysreset
USB: drv id 85 name reset
USB: drv id 22 name blk
USB: drv id 59 name mmc
USB: drv id 99 name syscon
USB: drv id 25 name cache
USB: drv id 43 name i2c
USB: drv id 40 name gpio
USB: drv id 36 name ethernet
USB: drv id 91 name simple_bus
USB: drv id 0 name root
No working controllers found

The function "uclass_find()" does no longer find the USB host device (UCLASS_USB). The debug ouput is with:

drivers/core/uclass.c +3 -0
index 2578803b7a..b59a5dcdad 100644
@@ -35,6 +35,9 @@ struct uclass *uclass_find(enum uclass_id key)
          * id to node.
          */
         list_for_each_entry(uc, gd->uclass_root, sibling_node) {
+               if (key == UCLASS_USB)
+                       printf("USB: drv id %d name %s\n",
+                              uc->uc_drv->id, uc->uc_drv->name);
                 if (uc->uc_drv->id == key)
                         return uc;
         }
Quoted 3 lines

Id 110 is UCLASS_USB_GADGET_GENERIC, but UCLASS_USB is gone. There is some magic with usb device scanning. Any idea what could cause that problem?

+CC Simon