Skip to contentSkip to conversation

imx: add macro to detect whether USB PHY is active

PATCH Superseded Stefan Agner 3 participants 9 messages Sep 8, 2017 – Sep 9, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 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 v2 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 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..f3fec81de7 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 descided 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) initialized 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 v2 2/2 imx_common: detect USB serial downloader reliably

Hi Stefan,

Quoted 33 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 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..f3fec81de7 100644

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

Quoted 8 lines
arch/arm/mach-imx/spl.c +5 -0
@@ -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 descided to use the
+	 * serial downloader as a fall back (primary boot source failed).
+	 *

Nit: should be "did not initialize" instead of "initialized".

Otherwise, this is a nice comment that describes the situation.

Quoted 11 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) initialized 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 */
#3 lore raw

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

Quoted 31 lines · Eric Nelson

Hi Stefan,

Quoted 28 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 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 14 lines

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

Quoted 12 lines
arch/arm/mach-imx/spl.c +4 -0
index 258578ac25..f3fec81de7 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 descided to use the
+	 * serial downloader as a fall back (primary boot source failed).
+	 *

Nit: should be "did not initialize" instead of "initialized".

Sorry, don't get that. Below I write "did not (yet) initialized"...

--
Stefan

Quoted 14 lines

Otherwise, this is a nice comment that describes the situation.

Quoted 11 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) initialized 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 */
#4 lore raw

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

Hi Stefan,

Quoted 4 lines · Stefan Agner
Quoted 3 lines · Eric Nelson
Quoted 2 lines · Stefan Agner

From: Stefan Agner <[email protected]>

<snip>

Quoted 5 lines
Quoted 2 lines

Nit: should be "did not initialize" instead of "initialized".

Sorry, don't get that. Below I write "did not (yet) initialized"...

The proper English usage here is "did not (yet) initialize".

You don't need the past tense after "did not".

reviewer
#5 lore raw

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

In reply to Stefan Agner

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

Quoted 3 lines · Stefan Agner
arch/arm/mach-imx/spl.c +3 -0
+       /*
+        * The above method does not detect that the boot ROM used
+        * serial downloader in case the boot ROM descided to use the

Typo: decided

#6 lore raw

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

Hi Stefan,

Quoted 8 lines · Fabio Estevam

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

Quoted 3 lines · Stefan Agner
arch/arm/mach-imx/spl.c +3 -0
+       /*
+        * The above method does not detect that the boot ROM used
+        * serial downloader in case the boot ROM descided to use the 

Typo: decided

You know you're on the right track when the only comments about your patch are about naming, spelling and grammar ;)

#7 lore raw

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

Quoted 9 lines · Eric Nelson

Hi Stefan,

Quoted 6 lines · Fabio Estevam
Quoted 3 lines · Stefan Agner
arch/arm/mach-imx/spl.c +3 -0
+       /*
+        * The above method does not detect that the boot ROM used
+        * serial downloader in case the boot ROM descided to use the
Quoted 5 lines
Quoted 2 lines

Typo: decided

You know you're on the right track when the only comments about your patch are about naming, spelling and grammar ;)

Hehe, ok cool.

Yeah my parser was searching for a logical issue wrt initialize... :-)

--
Stefan

#8 lore raw

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

In reply to Stefan Agner

Hi Stefan,

Quoted 30 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 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 13

Quoted 8 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +5 -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 */
+

At least MX6 and MX7 have USB Host PHY as well as USB OTG.

How about is_otgphy_active() instead?

Quoted 3 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +2 -0
+#define is_usbphy_active(void)	(!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \
+				   USBPHY_PWD_RXPWDRX))