Skip to contentSkip to conversation

imx: add macro to detect whether USB PHY is active

PATCH New Stefan Agner 3 participants 10 messages Sep 13, 2017 – Sep 20, 2017

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

PATCH v3 1/2 imx: add macro to detect whether USB PHY is active

From: Stefan Agner <[email protected]>

This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader.

The idea is taken from the mfgtool support in the NXP U-Boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3: None
Changes in v2:
- Move macro to sys_proto.h
- Renamed from is_boot_from_usb() to is_usbphy_active()
- Use defines for register offset and field
- Remove tab after define
- Remove comment since the actual "magic" is happening and documented at usage side

 arch/arm/include/asm/arch-mx6/sys_proto.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/include/asm/arch-mx6/sys_proto.h +7 -0
index 14f5d948c9..ba73943260 100644
@@ -6,3 +6,10 @@
  */
 
 #include <asm/mach-imx/sys_proto.h>
+
+#define USBPHY_PWD		0x00000000
+
+#define USBPHY_PWD_RXPWDRX	(1 << 20) /* receiver block power down */
+
+#define is_usbotg_phy_active(void) (!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \
+				   USBPHY_PWD_RXPWDRX))
Signature · 1 line
2.14.1
#1 lore raw

PATCH v3 1/2 imx: add macro to detect whether USB PHY is active

Sorry, the subject should have been v4.

--
Stefan

Quoted 46 lines · Stefan Agner

From: Stefan Agner <[email protected]>

This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader.

The idea is taken from the mfgtool support in the NXP U-Boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3: None
Changes in v2:
- Move macro to sys_proto.h
- Renamed from is_boot_from_usb() to is_usbphy_active()
- Use defines for register offset and field
- Remove tab after define
- Remove comment since the actual "magic" is happening and documented at usage side

 arch/arm/include/asm/arch-mx6/sys_proto.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/include/asm/arch-mx6/sys_proto.h +6 -0
index 14f5d948c9..ba73943260 100644
@@ -6,3 +6,10 @@
  */
 
 #include <asm/mach-imx/sys_proto.h>
+
+#define USBPHY_PWD		0x00000000
+
+#define USBPHY_PWD_RXPWDRX	(1 << 20) /* receiver block power down */
+
+#define is_usbotg_phy_active(void) (!(readl(USB_PHY0_BASE_ADDR +

USBPHY_PWD) & \

arch/arm/include/asm/arch-mx6/sys_proto.h +1 -0
+				   USBPHY_PWD_RXPWDRX))
Quoted 46 lines · Stefan Agner

From: Stefan Agner <[email protected]>

This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader.

The idea is taken from the mfgtool support in the NXP U-Boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3: None
Changes in v2:
- Move macro to sys_proto.h
- Renamed from is_boot_from_usb() to is_usbphy_active()
- Use defines for register offset and field
- Remove tab after define
- Remove comment since the actual "magic" is happening and documented at usage side

 arch/arm/include/asm/arch-mx6/sys_proto.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/include/asm/arch-mx6/sys_proto.h +6 -0
index 14f5d948c9..ba73943260 100644
@@ -6,3 +6,10 @@
  */
 
 #include <asm/mach-imx/sys_proto.h>
+
+#define USBPHY_PWD		0x00000000
+
+#define USBPHY_PWD_RXPWDRX	(1 << 20) /* receiver block power down */
+
+#define is_usbotg_phy_active(void) (!(readl(USB_PHY0_BASE_ADDR +

USBPHY_PWD) & \

arch/arm/include/asm/arch-mx6/sys_proto.h +1 -0
+				   USBPHY_PWD_RXPWDRX))
#2 lore raw

PATCH v3 2/2 imx_common: detect USB serial downloader reliably

In reply to Stefan Agner

From: Stefan Agner <[email protected]>

The current mechanism using SCR/GPR registers work well when the serial downloader boot mode has been selected explicitly (either via boot mode pins or using bmode command). However, in case the system entered boot ROM due to unbootable primary boot devices (e.g. empty eMMC), the SPL fails to detect that it has been downloaded through serial loader and tries to continue booting from eMMC:
Trying to boot from MMC1
mmc_load_image_raw_sector: mmc block read error
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

The only known way to reliably detect USB serial downloader is by checking the USB PHY receiver block power state...

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3:
- Fix spelling and grammar

Changes in v2:
- Add comment that we infer boot ROM behavior from USB PHY state

 arch/arm/mach-imx/spl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm/mach-imx/spl.c +12 -0
index 258578ac25..534cc6504d 100644
@@ -31,6 +31,18 @@ u32 spl_boot_device(void)
 	if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
 		return BOOT_DEVICE_BOARD;
 
+	/*
+	 * The above method does not detect that the boot ROM used
+	 * serial downloader in case the boot ROM decided to use the
+	 * serial downloader as a fall back (primary boot source failed).
+	 *
+	 * Infer that the boot ROM used the USB serial downloader by
+	 * checking whether the USB PHY is currently active... This
+	 * assumes that SPL did not (yet) initialize the USB PHY...
+	 */
+	if (is_otgusb_phy_active())
+		return BOOT_DEVICE_BOARD;
+
 	/* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
 	switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
 	 /* EIM: See 8.5.1, Table 8-9 */
Signature · 1 line
2.14.1
#3 lore raw

PATCH v3 2/2 imx_common: detect USB serial downloader reliably

Hi Stefan,

Thanks for this patch.

Quoted 48 lines · Stefan Agner

From: Stefan Agner <[email protected]>

The current mechanism using SCR/GPR registers work well when the serial downloader boot mode has been selected explicitly (either via boot mode pins or using bmode command). However, in case the system entered boot ROM due to unbootable primary boot devices (e.g. empty eMMC), the SPL fails to detect that it has been downloaded through serial loader and tries to continue booting from eMMC:
Trying to boot from MMC1
mmc_load_image_raw_sector: mmc block read error
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

The only known way to reliably detect USB serial downloader is by checking the USB PHY receiver block power state...

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3:
- Fix spelling and grammar

Changes in v2:
- Add comment that we infer boot ROM behavior from USB PHY state

  arch/arm/mach-imx/spl.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
arch/arm/mach-imx/spl.c +5 -0
index 258578ac25..534cc6504d 100644
@@ -31,6 +31,18 @@ u32 spl_boot_device(void)
  	if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
  		return BOOT_DEVICE_BOARD;
 
+	/*
+	 * The above method does not detect that the boot ROM used
+	 * serial downloader in case the boot ROM decided to use the
+	 * serial downloader as a fall back (primary boot source failed).
+	 *

arch/arm/mach-imx/spl.c u32 spl_boot_device(void) · line 48

Quoted 10 lines
arch/arm/mach-imx/spl.c +7 -0
+	 * Infer that the boot ROM used the USB serial downloader by
+	 * checking whether the USB PHY is currently active... This
+	 * assumes that SPL did not (yet) initialize the USB PHY...
+	 */
+	if (is_otgusb_phy_active())
+		return BOOT_DEVICE_BOARD;
+
  	/* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
  	switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
  	 /* EIM: See 8.5.1, Table 8-9 */
#4 lore raw

PATCH v3 2/2 imx_common: detect USB serial downloader reliably

Hi Stefan,

Quoted 48 lines · Eric Nelson

Hi Stefan,

Thanks for this patch.

Quoted 43 lines · Stefan Agner

From: Stefan Agner <[email protected]>

The current mechanism using SCR/GPR registers work well when the serial downloader boot mode has been selected explicitly (either via boot mode pins or using bmode command). However, in case the system entered boot ROM due to unbootable primary boot devices (e.g. empty eMMC), the SPL fails to detect that it has been downloaded through serial loader and tries to continue booting from eMMC:
   Trying to boot from MMC1
   mmc_load_image_raw_sector: mmc block read error
   SPL: failed to boot from all boot devices
   ### ERROR ### Please RESET the board ###

The only known way to reliably detect USB serial downloader is by checking the USB PHY receiver block power state...

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3:
- Fix spelling and grammar

Changes in v2:
- Add comment that we infer boot ROM behavior from USB PHY state

  arch/arm/mach-imx/spl.c | 12 ++++++++++++

  1 file changed, 12 insertions(+)
arch/arm/mach-imx/spl.c +0 -0
index 258578ac25..534cc6504d 100644
@@ -31,6 +31,18 @@ u32 spl_boot_device(void)

      if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */ return BOOT_DEVICE_BOARD;
  +    /*
+     * The above method does not detect that the boot ROM used

Quoted 8 lines
Quoted 8 lines

+     * serial downloader in case the boot ROM decided to use the +     * serial downloader as a fall back (primary boot source failed). +     *
+     * Infer that the boot ROM used the USB serial downloader by +     * checking whether the USB PHY is currently active... This +     * assumes that SPL did not (yet) initialize the USB PHY... +     */
+    if (is_otgusb_phy_active())

This is "otgusb", but in sys_proto.h is "usbotg".

Can I fix it myself as "usbotg" by merging ?

Best regards,
Stefano

Quoted 8 lines
Quoted 6 lines

+        return BOOT_DEVICE_BOARD;
+
      /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */ switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { /* EIM: See 8.5.1, Table 8-9 */

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#5 lore raw

PATCH v3 2/2 imx_common: detect USB serial downloader reliably

Quoted 61 lines · Stefano Babic

Hi Stefan,

Quoted 39 lines · Eric Nelson

Hi Stefan,

Thanks for this patch.

Quoted 34 lines · Stefan Agner

From: Stefan Agner <[email protected]>

The current mechanism using SCR/GPR registers work well when the serial downloader boot mode has been selected explicitly (either via boot mode pins or using bmode command). However, in case the system entered boot ROM due to unbootable primary boot devices (e.g. empty eMMC), the SPL fails to detect that it has been downloaded through serial loader and tries to continue booting from eMMC:
   Trying to boot from MMC1
   mmc_load_image_raw_sector: mmc block read error
   SPL: failed to boot from all boot devices
   ### ERROR ### Please RESET the board ###

The only known way to reliably detect USB serial downloader is by checking the USB PHY receiver block power state...

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3:
- Fix spelling and grammar

Changes in v2:
- Add comment that we infer boot ROM behavior from USB PHY state

  arch/arm/mach-imx/spl.c | 12 ++++++++++++

  1 file changed, 12 insertions(+)
Quoted 11 lines
Quoted 11 lines
arch/arm/mach-imx/spl.c +0 -0
index 258578ac25..534cc6504d 100644
@@ -31,6 +31,18 @@ u32 spl_boot_device(void)

      if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */ return BOOT_DEVICE_BOARD;
  +    /*
+     * The above method does not detect that the boot ROM used +     * serial downloader in case the boot ROM decided to use the +     * serial downloader as a fall back (primary boot source

failed).

Quoted 6 lines
Quoted 6 lines

+     *
+     * Infer that the boot ROM used the USB serial downloader by +     * checking whether the USB PHY is currently active... This +     * assumes that SPL did not (yet) initialize the USB PHY... +     */
+    if (is_otgusb_phy_active())

Quoted 3 lines

This is "otgusb", but in sys_proto.h is "usbotg".

Can I fix it myself as "usbotg" by merging ?

Good point, wonder why I did not notice, I usually build it again. Sure go ahead.

--
Stefan

Quoted 12 lines

Best regards,
Stefano

Quoted 8 lines
Quoted 6 lines

+        return BOOT_DEVICE_BOARD;
+
      /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */ switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { /* EIM: See 8.5.1, Table 8-9 */

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#6 lore raw

PATCH v3 2/2 imx_common: detect USB serial downloader reliably

In reply to Stefan Agner
Quoted 14 lines · Stefan Agner

From: Stefan Agner <[email protected]>

The current mechanism using SCR/GPR registers work well when the serial downloader boot mode has been selected explicitly (either via boot mode pins or using bmode command). However, in case the system entered boot ROM due to unbootable primary boot devices (e.g. empty eMMC), the SPL fails to detect that it has been downloaded through serial loader and tries to continue booting from eMMC:
Trying to boot from MMC1
mmc_load_image_raw_sector: mmc block read error
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Quoted 7 lines

The only known way to reliably detect USB serial downloader is by checking the USB PHY receiver block power state...

---

Applied to u-boot-imx, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#7 lore raw

PATCH v3 1/2 imx: add macro to detect whether USB PHY is active

In reply to Stefan Agner
Quoted 34 lines · Stefan Agner

From: Stefan Agner <[email protected]>

This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader.

The idea is taken from the mfgtool support in the NXP U-Boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3: None
Changes in v2:
- Move macro to sys_proto.h
- Renamed from is_boot_from_usb() to is_usbphy_active()
- Use defines for register offset and field
- Remove tab after define
- Remove comment since the actual "magic" is happening and documented at usage side

  arch/arm/include/asm/arch-mx6/sys_proto.h | 7 +++++++
  1 file changed, 7 insertions(+)
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 14f5d948c9..ba73943260 100644

arch/arm/include/asm/arch-mx6/sys_proto.h line 8

Quoted 3 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
@@ -6,3 +6,10 @@
   */
 
  #include <asm/mach-imx/sys_proto.h>

I'd be more worried about these macro names (asking that they also include "OTG") if they weren't defined in such close proximity to their only use.

arch/arm/include/asm/arch-mx6/sys_proto.h line 15

Quoted 8 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +7 -0
+
+#define USBPHY_PWD		0x00000000
+
+#define USBPHY_PWD_RXPWDRX	(1 << 20) /* receiver block power down */
+
+#define is_usbotg_phy_active(void) (!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \
+				   USBPHY_PWD_RXPWDRX))

Otherwise,

#8 lore raw

PATCH v3 1/2 imx: add macro to detect whether USB PHY is active

Quoted 30 lines · Eric Nelson
Quoted 29 lines · Stefan Agner

From: Stefan Agner <[email protected]>

This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader.

The idea is taken from the mfgtool support in the NXP U-Boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412

---

Changes in v4:
- Rename macro to is_usbotg_phy_active()

Changes in v3: None
Changes in v2:
- Move macro to sys_proto.h
- Renamed from is_boot_from_usb() to is_usbphy_active()
- Use defines for register offset and field
- Remove tab after define
- Remove comment since the actual "magic" is happening and documented at usage side

  arch/arm/include/asm/arch-mx6/sys_proto.h | 7 +++++++
  1 file changed, 7 insertions(+)
Quoted 12 lines

arch/arm/include/asm/arch-mx6/sys_proto.h line 7

Quoted 7 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 14f5d948c9..ba73943260 100644
@@ -6,3 +6,10 @@
   */
    #include <asm/mach-imx/sys_proto.h>

I'd be more worried about these macro names (asking that they also include "OTG") if they weren't defined in such close proximity to their only use.

The registers for the host and otg phy are the same, one might reuse them for host...

Quoted 8 lines

arch/arm/include/asm/arch-mx6/sys_proto.h

Quoted 8 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +7 -0
+
+#define USBPHY_PWD		0x00000000
+
+#define USBPHY_PWD_RXPWDRX	(1 << 20) /* receiver block power down */
+
+#define is_usbotg_phy_active(void) (!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \
+				   USBPHY_PWD_RXPWDRX))
 

In contrast, this function define is really OTG phy specific since we use PHY0.

Quoted 4 lines

Otherwise,

Thx!

--
Stefan

#9 lore raw

PATCH v3 1/2 imx: add macro to detect whether USB PHY is active

In reply to Stefan Agner
Quoted 6 lines · Stefan Agner

From: Stefan Agner <[email protected]>

This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader.

Quoted 7 lines

The idea is taken from the mfgtool support in the NXP U-Boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412

---

Applied to u-boot-imx, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================