Skip to contentSkip to conversation

imx: add macro to detect whether USB PHY is active

PATCH Superseded Stefan Agner 4 participants 7 messages Sep 12, 2017 – Sep 13, 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 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..9d4b1d6768 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_usbphy_active(void)	(!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \
+				   USBPHY_PWD_RXPWDRX))
Signature · 1 line
2.14.1
#1 lore raw

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

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 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..522ab9f260 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_usbphy_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
#2 lore raw

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

In reply to Stefan Agner

Hi Stefan,

I hate to be fussy about this, but I don't think I saw a reply to my earlier comment about the term "USB PHY".

https://lists.denx.de/pipermail/u-boot/2017-September/305123.html

Since i.MX6 SoCs have USB **Host** Phy's as well as the USB OTG Phy, this patch is a bit misleading.

There's no reference to OTG anywhere in this or patch 2.

Quoted 32 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 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..9d4b1d6768 100644

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

Quoted 10 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +7 -0
@@ -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_usbphy_active(void)	(!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \
+				   USBPHY_PWD_RXPWDRX))

Regards,

Eric

#3 lore raw

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

Hi Eric, Stefan,

Quoted 5 lines · Eric Nelson

Hi Stefan,

I hate to be fussy about this, but I don't think I saw a reply to my earlier comment about the term "USB PHY".

Quoted 7 lines

https://lists.denx.de/pipermail/u-boot/2017-September/305123.html

Since i.MX6 SoCs have USB **Host** Phy's as well as the USB OTG Phy, this patch is a bit misleading.

There's no reference to OTG anywhere in this or patch 2.

To be consistent with the names, Eric is right. We have PHY0 for OTG and PHY1 for Host. If you still want to use as name is_usbphy_active, then this should take as parameter the phy number, or you switch to a "otg" name to ensure that it is only for the OTG interface.

Best regards,
Stefano

Quoted 50 lines · Stefan Agner
Quoted 34 lines

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 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..9d4b1d6768 100644

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

Quoted 10 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +7 -0
@@ -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_usbphy_active(void)    (!(readl(USB_PHY0_BASE_ADDR +
 USBPHY_PWD) & \
+                   USBPHY_PWD_RXPWDRX))

Regards,

Eric

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
=====================================================================
#4 lore raw

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

Quoted 15 lines · Stefano Babic

Hi Eric, Stefan,

Quoted 12 lines · Eric Nelson

Hi Stefan,

I hate to be fussy about this, but I don't think I saw a reply to my earlier comment about the term "USB PHY".

https://lists.denx.de/pipermail/u-boot/2017-September/305123.html

Since i.MX6 SoCs have USB **Host** Phy's as well as the USB OTG Phy, this patch is a bit misleading.

There's no reference to OTG anywhere in this or patch 2.

Hm, sorry I missed that.

Quoted 5 lines

To be consistent with the names, Eric is right. We have PHY0 for OTG and PHY1 for Host. If you still want to use as name is_usbphy_active, then this should take as parameter the phy number, or you switch to a "otg" name to ensure that it is only for the OTG interface.

For the registers itself I followed the notation used in chapter 66 and arch/arm/include/asm/arch-mx6/imx-regs.h.

Renaming the function macro makes sense I agree.

The USB serial downloader only works with the OTG USB PHY anyway, so I will rename it. I like to have USB still in there, how about:

is_usbotg_phy_active()

--
Stefan

Quoted 54 lines

Best regards,
Stefano

Quoted 50 lines · Stefan Agner
Quoted 34 lines

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 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..9d4b1d6768 100644

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

Quoted 10 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +7 -0
@@ -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_usbphy_active(void)    (!(readl(USB_PHY0_BASE_ADDR +
 USBPHY_PWD) & \
+                   USBPHY_PWD_RXPWDRX))

Regards,

Eric

reviewer
#5 lore raw

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

Quoted 4 lines · Stefan Agner

The USB serial downloader only works with the OTG USB PHY anyway, so I will rename it. I like to have USB still in there, how about:

is_usbotg_phy_active()

Looks fine. Please send a v4 with it and we should be good :-)

#6 lore raw

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

In reply to Stefan Agner

Hi Stefan,

Quoted 11 lines · Stefan Agner
Quoted 10 lines · Stefano Babic

Hi Eric, Stefan,

Quoted 7 lines · Eric Nelson

Hi Stefan,

I hate to be fussy about this, but I don't think I saw a reply to my earlier comment about the term "USB PHY".

https://lists.denx.de/pipermail/u-boot/2017-September/305123.html

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Since i.MX6 SoCs have USB **Host** Phy's as well as the USB OTG Phy, this patch is a bit misleading.

There's no reference to OTG anywhere in this or patch 2.

Hm, sorry I missed that.

No worries. We're here to nag...

Quoted 9 lines
Quoted 5 lines

To be consistent with the names, Eric is right. We have PHY0 for OTG and PHY1 for Host. If you still want to use as name is_usbphy_active, then this should take as parameter the phy number, or you switch to a "otg" name to ensure that it is only for the OTG interface.

For the registers itself I followed the notation used in chapter 66 and arch/arm/include/asm/arch-mx6/imx-regs.h.

Quoted 7 lines

Renaming the function macro makes sense I agree.

The USB serial downloader only works with the OTG USB PHY anyway, so I will rename it. I like to have USB still in there, how about:

is_usbotg_phy_active()

Perfect.