Skip to contentSkip to conversation

Add power management support for MXS PHY

PATCH New Peter Chen 4 participants 32 messages Oct 12, 2013 – Oct 14, 2013

Subsystems (3)
lore
Share & tools
lore

Peter Chen

author
#0 lore raw

cover Add power management support for MXS PHY

Hi Felipe,

The serial adds power management support for MXS PHY, it includes:

- Add three common PHY API, .set_wakeup, .notify_suspend, notify_resume.
- Related above API implementation at mxs phy driver
- misc changes for mxs phy to support low power mode and wakeup.

Hi Shawn,

The last four are devicetree related patches to support above mxs phy features.

Peter Chen (12):
usb: phy-mxs: Add auto clock and power setting
usb: phy-mxs: Enable IC fixes for mx6 SoC serial
usb: phy-mxs: Add anatop regmap
usb: phy: add notify suspend and resume callback
usb: phy-mxs: Add implementation of nofity_suspend and notify_resume
usb: phy: Add set_wakeup API
usb: phy-mxs: Add implementation of set_wakeup
usb: phy-mxs: Add system suspend/resume API
usb: phy-mxs: update binding for adding anatop phandle
ARM: dts: imx6: add anatop phandle for usbphy
usb: phy-mxs: update binding for adding disconnect line property
ARM: dts: imx6: Add disconnect_line_without_vbus property for usbphy

 Documentation/devicetree/bindings/usb/mxs-phy.txt |    6 +
 arch/arm/boot/dts/imx6qdl.dtsi                    |    3 +
 drivers/usb/phy/phy-mxs-usb.c                     |  247 ++++++++++++++++++++-
 include/linux/usb/phy.h                           |   39 ++++
 4 files changed, 291 insertions(+), 4 deletions(-)
author
#1 lore raw

PATCH 1/12 usb: phy-mxs: Add auto clock and power setting

With the auto setting, the PHY's clock and power can be recovered correctly from low power mode, it is ganranteed by IC logic.

---
 drivers/usb/phy/phy-mxs-usb.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +17 -3
index a0628d6..87ba429 100644
@@ -31,6 +31,11 @@
 
 #define BM_USBPHY_CTRL_SFTRST			BIT(31)
 #define BM_USBPHY_CTRL_CLKGATE			BIT(30)
+#define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS	BIT(26)
+#define BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE	BIT(25)
+#define BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD	BIT(20)
+#define BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE	BIT(19)
+#define BM_USBPHY_CTRL_ENAUTO_PWRON_PLL		BIT(18)
 #define BM_USBPHY_CTRL_ENUTMILEVEL3		BIT(15)
 #define BM_USBPHY_CTRL_ENUTMILEVEL2		BIT(14)
 #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	BIT(1)
@@ -99,9 +104,18 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
 	/* Power up the PHY */
 	writel(0, base + HW_USBPHY_PWD);
 
-	/* enable FS/LS device */
-	writel(BM_USBPHY_CTRL_ENUTMILEVEL2 |
-	       BM_USBPHY_CTRL_ENUTMILEVEL3,
+	/*
+	 * USB PHY Ctrl Setting
+	 * - Auto clock/power on
+	 * - Enable full/low speed support
+	 */
+	writel(BM_USBPHY_CTRL_ENAUTOSET_USBCLKS |
+		BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE |
+		BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD |
+		BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE |
+		BM_USBPHY_CTRL_ENAUTO_PWRON_PLL |
+		BM_USBPHY_CTRL_ENUTMILEVEL2 |
+		BM_USBPHY_CTRL_ENUTMILEVEL3,
 	       base + HW_USBPHY_CTRL_SET);
 
 	return 0;
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

In reply to Peter Chen

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

---
 drivers/usb/phy/phy-mxs-usb.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +10 -0
index 87ba429..831b13e 100644
@@ -29,6 +29,10 @@
 #define HW_USBPHY_CTRL_SET			0x34
 #define HW_USBPHY_CTRL_CLR			0x38
 
+#define HW_USBPHY_IP				0x90
+#define HW_USBPHY_IP_SET			0x94
+#define HW_USBPHY_IP_CLR			0x98
+
 #define BM_USBPHY_CTRL_SFTRST			BIT(31)
 #define BM_USBPHY_CTRL_CLKGATE			BIT(30)
 #define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS	BIT(26)
@@ -40,6 +44,8 @@
 #define BM_USBPHY_CTRL_ENUTMILEVEL2		BIT(14)
 #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	BIT(1)
 
+#define BM_USBPHY_IP_FIX                       (BIT(17) | BIT(18))
+
 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
 
 enum imx_phy_type {
@@ -118,6 +124,10 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
 		BM_USBPHY_CTRL_ENUTMILEVEL3,
 	       base + HW_USBPHY_CTRL_SET);
 
+	/* Enable IC solution */
+	if (is_mx6q_phy(mxs_phy) || is_mx6sl_phy(mxs_phy))
+		writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET);
+
 	return 0;
 }
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

Hi,

Quoted 2 lines

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

Can you please elaborate what those bits do exactly ? They seem like a magic stuff to me thus far, which is not exactly helpful . I can't find them in the datasheet either.

Quoted 30 lines
---
 drivers/usb/phy/phy-mxs-usb.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +6 -0
index 87ba429..831b13e 100644
@@ -29,6 +29,10 @@
 #define HW_USBPHY_CTRL_SET			0x34
 #define HW_USBPHY_CTRL_CLR			0x38
 
+#define HW_USBPHY_IP				0x90
+#define HW_USBPHY_IP_SET			0x94
+#define HW_USBPHY_IP_CLR			0x98
+
 #define BM_USBPHY_CTRL_SFTRST			BIT(31)
 #define BM_USBPHY_CTRL_CLKGATE			BIT(30)
 #define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS	BIT(26)
@@ -40,6 +44,8 @@
 #define BM_USBPHY_CTRL_ENUTMILEVEL2		BIT(14)
 #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	BIT(1)
 
+#define BM_USBPHY_IP_FIX                       (BIT(17) | BIT(18))
+
 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
 
 enum imx_phy_type {

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) · line 132

Quoted 9 lines
drivers/usb/phy/phy-mxs-usb.c +4 -0
@@ -118,6 +124,10 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
 		BM_USBPHY_CTRL_ENUTMILEVEL3,
 	       base + HW_USBPHY_CTRL_SET);
 
+	/* Enable IC solution */
+	if (is_mx6q_phy(mxs_phy) || is_mx6sl_phy(mxs_phy))
+		writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET);
+
 	return 0;
 }

Best regards,
Marek Vasut

author
#4 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

Quoted 9 lines · Marek Vasut

Hi,

Quoted 2 lines

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

Can you please elaborate what those bits do exactly ? They seem like a magic stuff to me thus far, which is not exactly helpful . I can't find them in the datasheet either.

Yes, these bits are added at late TO verion for i.mx 6, and these TO versions will be for mass production, unfortunately, the related doc update may be forgotten.

These two bits are related to two PHY bugs, two PHY bugs are still existed at mx28 and mx23, one bug is fixed at mx6dq and mx6dl, and both of two bugs are fixed at later mx6 (like mx6sololite and later SoCs), but the IC fixes are not enabled by default, it needs software opens it.

Signature · 2 lines
Best Regards,
Peter Chen
#5 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

Dear Peter Chen,

Quoted 10 lines · Marek Vasut
Quoted 8 lines

Hi,

Quoted 2 lines

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

Can you please elaborate what those bits do exactly ? They seem like a magic stuff to me thus far, which is not exactly helpful . I can't find them in the datasheet either.

Quoted 8 lines

Yes, these bits are added at late TO verion for i.mx 6, and these TO versions will be for mass production, unfortunately, the related doc update may be forgotten.

These two bits are related to two PHY bugs, two PHY bugs are still existed at mx28 and mx23, one bug is fixed at mx6dq and mx6dl, and both of two bugs are fixed at later mx6 (like mx6sololite and later SoCs), but the IC fixes are not enabled by default, it needs software opens it.

Sure, I get it. But what exactly does that bit do? Can you add a proper (and likely beefy) comment into the code to supplement the missing parts in the datasheet?

Best regards,
Marek Vasut

author
#6 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

Quoted 16 lines · Marek Vasut

Dear Peter Chen,

Quoted 14 lines · Marek Vasut
Quoted 8 lines

Hi,

Quoted 2 lines

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

Can you please elaborate what those bits do exactly ? They seem like a magic stuff to me thus far, which is not exactly helpful . I can't find them in the datasheet either.

Yes, these bits are added at late TO verion for i.mx 6, and these TO versions will be for mass production, unfortunately, the related doc update may be forgotten.

Quoted 8 lines
Quoted 4 lines

These two bits are related to two PHY bugs, two PHY bugs are still existed at mx28 and mx23, one bug is fixed at mx6dq and mx6dl, and both of two bugs are fixed at later mx6 (like mx6sololite and later SoCs), but the IC fixes are not enabled by default, it needs software opens it.

Sure, I get it. But what exactly does that bit do? Can you add a proper (and likely beefy) comment into the code to supplement the missing parts in the datasheet?

OK, I will add them at v2.

Signature · 2 lines
Best Regards,
Peter Chen
#7 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

In reply to Peter Chen
Quoted 33 lines · Peter Chen

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

---
 drivers/usb/phy/phy-mxs-usb.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +6 -0
index 87ba429..831b13e 100644
@@ -29,6 +29,10 @@
 #define HW_USBPHY_CTRL_SET			0x34
 #define HW_USBPHY_CTRL_CLR			0x38
 
+#define HW_USBPHY_IP				0x90
+#define HW_USBPHY_IP_SET			0x94
+#define HW_USBPHY_IP_CLR			0x98
+
 #define BM_USBPHY_CTRL_SFTRST			BIT(31)
 #define BM_USBPHY_CTRL_CLKGATE			BIT(30)
 #define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS	BIT(26)
@@ -40,6 +44,8 @@
 #define BM_USBPHY_CTRL_ENUTMILEVEL2		BIT(14)
 #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	BIT(1)
 
+#define BM_USBPHY_IP_FIX                       (BIT(17) | BIT(18))
+
 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
 
 enum imx_phy_type {

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) · line 128

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +2 -0
@@ -118,6 +124,10 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
 		BM_USBPHY_CTRL_ENUTMILEVEL3,
 	       base + HW_USBPHY_CTRL_SET);
 
+	/* Enable IC solution */
+	if (is_mx6q_phy(mxs_phy) || is_mx6sl_phy(mxs_phy))

Am I missing any dependency/patches here? Where were is_mx6q_phy() and is_mx6sl_phy() introduced?

Shawn

Quoted 9 lines
drivers/usb/phy/phy-mxs-usb.c +2 -0
+		writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET);
+
 	return 0;
 }
 
Signature · 1 line
1.7.1
author
#8 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

Quoted 50 lines · Shawn Guo
Quoted 33 lines · Peter Chen

After adding IC fixes bits, some PHY bugs are fixed by IC logic.

---
 drivers/usb/phy/phy-mxs-usb.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +6 -0
index 87ba429..831b13e 100644
@@ -29,6 +29,10 @@
 #define HW_USBPHY_CTRL_SET			0x34
 #define HW_USBPHY_CTRL_CLR			0x38
 
+#define HW_USBPHY_IP				0x90
+#define HW_USBPHY_IP_SET			0x94
+#define HW_USBPHY_IP_CLR			0x98
+
 #define BM_USBPHY_CTRL_SFTRST			BIT(31)
 #define BM_USBPHY_CTRL_CLKGATE			BIT(30)
 #define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS	BIT(26)
@@ -40,6 +44,8 @@
 #define BM_USBPHY_CTRL_ENUTMILEVEL2		BIT(14)
 #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	BIT(1)
 
+#define BM_USBPHY_IP_FIX                       (BIT(17) | BIT(18))
+
 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
 
 enum imx_phy_type {

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) · line 128

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +2 -0
@@ -118,6 +124,10 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
 		BM_USBPHY_CTRL_ENUTMILEVEL3,
 	       base + HW_USBPHY_CTRL_SET);
 
+	/* Enable IC solution */
+	if (is_mx6q_phy(mxs_phy) || is_mx6sl_phy(mxs_phy))

Am I missing any dependency/patches here? Where were is_mx6q_phy() and is_mx6sl_phy() introduced?

Shawn

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +2 -0
+		writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET);
+
 	return 0;
 }
 
Quoted 4 lines
Quoted 4 lines
Signature · 1 line
1.7.1

Oh, sorry. I forget to put below one to this serial. Will do at v2

http://marc.info/?l=linux-usb&m=137871552016298&w=2

Signature · 2 lines
Best Regards,
Peter Chen
author
#10 lore raw

PATCH 2/12 usb: phy-mxs: Enable IC fixes for mx6 SoC serial

Quoted 8 lines · Shawn Guo
Quoted 4 lines · Peter Chen

Oh, sorry. I forget to put below one to this serial. Will do at v2

http://marc.info/?l=linux-usb&m=137871552016298&w=2

Remember to document the new compatible strings in bindings doc.

Will do, thanks

Signature · 2 lines
Best Regards,
Peter Chen
author
#11 lore raw

PATCH 3/12 usb: phy-mxs: Add anatop regmap

In reply to Peter Chen

It is needed by mx6 SoC serial, but not for mx23 and mx28.

---
 drivers/usb/phy/phy-mxs-usb.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +16 -1
index 831b13e..e0b0de0 100644
@@ -21,6 +21,8 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/of_device.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
 #define DRIVER_NAME "mxs_phy"
 
@@ -58,6 +60,7 @@ struct mxs_phy {
 	struct usb_phy phy;
 	struct clk *clk;
 	enum imx_phy_type devtype;
+	struct regmap *regmap_anatop;
 };
 
 static inline int is_mx6q_phy(struct mxs_phy *data)
@@ -203,9 +206,10 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	int ret;
 	const struct of_device_id *of_id =
 			of_match_device(mxs_phy_dt_ids, &pdev->dev);
+	struct device_node *np = pdev->dev.of_node;
 
 	/* This driver is DT-only version now */
-	if (!of_id)
+	if (!of_id || !np)
 		return -ENXIO;
 
 	pdev->id_entry = of_id->data;
@@ -228,6 +232,17 @@ static int mxs_phy_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
+	/* Some SoCs don't have anatop registers */
+	if (of_get_property(np, "fsl,anatop", NULL)) {
+		mxs_phy->regmap_anatop = syscon_regmap_lookup_by_phandle
+			(np, "fsl,anatop");
+		if (IS_ERR(mxs_phy->regmap_anatop)) {
+			dev_dbg(&pdev->dev,
+				"failed to find regmap for anatop\n");
+			return PTR_ERR(mxs_phy->regmap_anatop);
+		}
+	}
+
 	mxs_phy->phy.io_priv		= base;
 	mxs_phy->phy.dev		= &pdev->dev;
 	mxs_phy->phy.label		= DRIVER_NAME;
Signature · 1 line
1.7.1
author
#12 lore raw

PATCH 4/12 usb: phy: add notify suspend and resume callback

In reply to Peter Chen

They are used to notify PHY that the controller enters suspend or finishes resume.

---
 include/linux/usb/phy.h |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
include/linux/usb/phy.h +23 -0
index 6c0b1c5..a747960 100644
@@ -116,6 +116,11 @@ struct usb_phy {
 			enum usb_device_speed speed);
 	int	(*notify_disconnect)(struct usb_phy *x,
 			enum usb_device_speed speed);
+	int	(*notify_suspend)(struct usb_phy *x,
+			enum usb_device_speed speed);
+	int	(*notify_resume)(struct usb_phy *x,
+			enum usb_device_speed speed);
+
 };
 
 /**
@@ -282,6 +287,24 @@ usb_phy_notify_disconnect(struct usb_phy *x, enum usb_device_speed speed)
 		return 0;
 }
 
+static inline int usb_phy_notify_suspend
+	(struct usb_phy *x, enum usb_device_speed speed)
+{
+	if (x && x->notify_suspend)
+		return x->notify_suspend(x, speed);
+	else
+		return 0;
+}
+
+static inline int usb_phy_notify_resume
+	(struct usb_phy *x, enum usb_device_speed speed)
+{
+	if (x && x->notify_resume)
+		return x->notify_resume(x, speed);
+	else
+		return 0;
+}
+
 /* notifiers */
 static inline int
 usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
Signature · 1 line
1.7.1
author
#13 lore raw

PATCH 5/12 usb: phy-mxs: Add implementation of nofity_suspend and notify_resume

In reply to Peter Chen

Add notify_suspend and notify_resume according to different SoCs.

---
 drivers/usb/phy/phy-mxs-usb.c |   73 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +73 -0
index e0b0de0..8661dae 100644
@@ -197,6 +197,78 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
 	return 0;
 }
 
+static int mxs_phy_on_suspend_workaround(struct usb_phy *phy,
+		enum usb_device_speed speed)
+{
+	dev_dbg(phy->dev, "%s speed device has suspended\n",
+		(speed == USB_SPEED_HIGH) ? "high" : "non-high");
+
+	/* delay 4ms to wait bus entering idle */
+	usleep_range(4000, 5000);
+
+	/*
+	 * Workaround for wakeup signal between portsc.suspendM
+	 * and PHY enters low power mode.
+	 */
+	writel_relaxed(0xffffffff, phy->io_priv + HW_USBPHY_PWD);
+	writel_relaxed(0, phy->io_priv + HW_USBPHY_PWD);
+
+	if (speed == USB_SPEED_HIGH)
+		writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+				phy->io_priv + HW_USBPHY_CTRL_CLR);
+
+	return 0;
+}
+
+static int mxs_phy_on_suspend(struct usb_phy *phy,
+		enum usb_device_speed speed)
+{
+	dev_dbg(phy->dev, "%s speed device has suspended\n",
+		(speed == USB_SPEED_HIGH) ? "high" : "non-high");
+
+	if (speed == USB_SPEED_HIGH)
+		writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+				phy->io_priv + HW_USBPHY_CTRL_CLR);
+
+	return 0;
+}
+
+/*
+ * The resume signal must be finished here.
+ */
+static int mxs_phy_on_resume(struct usb_phy *phy,
+		enum usb_device_speed speed)
+{
+	dev_dbg(phy->dev, "%s speed device has resumed\n",
+		(speed == USB_SPEED_HIGH) ? "high" : "non-high");
+
+	if (speed == USB_SPEED_HIGH) {
+		/* Make sure the device has switched to High-Speed mode */
+		udelay(500);
+		writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+				phy->io_priv + HW_USBPHY_CTRL_SET);
+	}
+
+	return 0;
+}
+
+/*
+ * For mxs PHY, there are two PHY issues related to suspend/resume.
+ * For mx23 and mx28, both of two issues are existed.
+ * For mx6q and mx6dl, only one issue is existed.
+ * For mx6 sololite, none issue is existed.
+ */
+static void mxs_phy_workaround(struct mxs_phy *mxs_phy)
+{
+	if (is_mx23_phy(mxs_phy)) {
+		mxs_phy->phy.notify_suspend = mxs_phy_on_suspend_workaround;
+		mxs_phy->phy.notify_resume = mxs_phy_on_resume;
+	} else if (is_mx6q_phy(mxs_phy)) {
+		mxs_phy->phy.notify_suspend = mxs_phy_on_suspend;
+		mxs_phy->phy.notify_resume = mxs_phy_on_resume;
+	}
+}
+
 static int mxs_phy_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -257,6 +329,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
 	mxs_phy->clk = clk;
 	mxs_phy->devtype = pdev->id_entry->driver_data;
+	mxs_phy_workaround(mxs_phy);
 
 	platform_set_drvdata(pdev, &mxs_phy->phy);
 
Signature · 1 line
1.7.1
#14 lore raw

PATCH 5/12 usb: phy-mxs: Add implementation of nofity_suspend and notify_resume

Dear Peter Chen,

Quoted 13 lines

Add notify_suspend and notify_resume according to different SoCs.

---
 drivers/usb/phy/phy-mxs-usb.c |   73

+++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-)

drivers/usb/phy/phy-mxs-usb.c +0 -0
index e0b0de0..8661dae 100644

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_on_disconnect(struct usb_phy *phy, · line 204

Quoted 8 lines
drivers/usb/phy/phy-mxs-usb.c +5 -0
@@ -197,6 +197,78 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
 	return 0;
 }
 
+static int mxs_phy_on_suspend_workaround(struct usb_phy *phy,
+		enum usb_device_speed speed)
+{
+	dev_dbg(phy->dev, "%s speed device has suspended\n",
+		(speed == USB_SPEED_HIGH) ? "high" : "non-high");

HS : FS/LS you mean?

Quoted 17 lines
drivers/usb/phy/phy-mxs-usb.c +17 -0
+
+	/* delay 4ms to wait bus entering idle */
+	usleep_range(4000, 5000);
+
+	/*
+	 * Workaround for wakeup signal between portsc.suspendM
+	 * and PHY enters low power mode.
+	 */
+	writel_relaxed(0xffffffff, phy->io_priv + HW_USBPHY_PWD);
+	writel_relaxed(0, phy->io_priv + HW_USBPHY_PWD);
+
+	if (speed == USB_SPEED_HIGH)
+		writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+				phy->io_priv + HW_USBPHY_CTRL_CLR);
+
+	return 0;
+}

[...]

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_on_disconnect(struct usb_phy *phy, · line 263

Quoted 9 lines
drivers/usb/phy/phy-mxs-usb.c +9 -0
+/*
+ * For mxs PHY, there are two PHY issues related to suspend/resume.
+ * For mx23 and mx28, both of two issues are existed.
+ * For mx6q and mx6dl, only one issue is existed.
+ * For mx6 sololite, none issue is existed.
+ */
+static void mxs_phy_workaround(struct mxs_phy *mxs_phy)
+{
+	if (is_mx23_phy(mxs_phy)) {

This is_mx23_phy() returns 1 for mx28 too? It's not too clear, not even from the comment above, a short comment here would help for sure.

Quoted 18 lines
drivers/usb/phy/phy-mxs-usb.c +9 -0
+		mxs_phy->phy.notify_suspend = mxs_phy_on_suspend_workaround;
+		mxs_phy->phy.notify_resume = mxs_phy_on_resume;
+	} else if (is_mx6q_phy(mxs_phy)) {
+		mxs_phy->phy.notify_suspend = mxs_phy_on_suspend;
+		mxs_phy->phy.notify_resume = mxs_phy_on_resume;
+	}
+}
+
 static int mxs_phy_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -257,6 +329,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
 	mxs_phy->clk = clk;
 	mxs_phy->devtype = pdev->id_entry->driver_data;
+	mxs_phy_workaround(mxs_phy);
 
 	platform_set_drvdata(pdev, &mxs_phy->phy);
author
#15 lore raw

PATCH 5/12 usb: phy-mxs: Add implementation of nofity_suspend and notify_resume

Quoted 18 lines · Marek Vasut

Dear Peter Chen,

Quoted 16 lines

Add notify_suspend and notify_resume according to different SoCs.

---
 drivers/usb/phy/phy-mxs-usb.c |   73

+++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-)

drivers/usb/phy/phy-mxs-usb.c +0 -0
index e0b0de0..8661dae 100644
@@ -197,6 +197,78 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
 	return 0;
 }
 
Quoted 7 lines

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_on_disconnect(struct usb_phy *phy, · line 204

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +5 -0
+static int mxs_phy_on_suspend_workaround(struct usb_phy *phy,
+		enum usb_device_speed speed)
+{
+	dev_dbg(phy->dev, "%s speed device has suspended\n",
+		(speed == USB_SPEED_HIGH) ? "high" : "non-high");

HS : FS/LS you mean?

Yes, it is what I mean.
OK, I will change to HS and FS/LS.

Quoted 13 lines

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_on_disconnect(struct usb_phy *phy, · line 263

Quoted 10 lines
drivers/usb/phy/phy-mxs-usb.c +9 -0
+/*
+ * For mxs PHY, there are two PHY issues related to suspend/resume.
+ * For mx23 and mx28, both of two issues are existed.
+ * For mx6q and mx6dl, only one issue is existed.
+ * For mx6 sololite, none issue is existed.
+ */
+static void mxs_phy_workaround(struct mxs_phy *mxs_phy)
+{
+	if (is_mx23_phy(mxs_phy)) {

This is_mx23_phy() returns 1 for mx28 too? It's not too clear, not even from the comment above, a short comment here would help for sure.

mx23 and mx28 PHY are the same PHY, so the fixes are the same. Anything I need to add?

Signature · 2 lines
Best Regards,
Peter Chen
#16 lore raw

PATCH 5/12 usb: phy-mxs: Add implementation of nofity_suspend and notify_resume

Dear Peter Chen,

Quoted 48 lines · Marek Vasut
Quoted 23 lines

Dear Peter Chen,

Quoted 21 lines

Add notify_suspend and notify_resume according to different SoCs.

---

 drivers/usb/phy/phy-mxs-usb.c |   73

+++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-)

(quoted diff) +0 -0

b/drivers/usb/phy/phy-mxs-usb.c index e0b0de0..8661dae 100644

drivers/usb/phy/phy-mxs-usb.c +0 -0
@@ -197,6 +197,78 @@ static int mxs_phy_on_disconnect(struct usb_phy
 *phy,
 
 	return 0;
 
 }
 
Quoted 7 lines

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_on_disconnect(struct usb_phy *phy, · line 204

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +5 -0
+static int mxs_phy_on_suspend_workaround(struct usb_phy *phy,
+		enum usb_device_speed speed)
+{
+	dev_dbg(phy->dev, "%s speed device has suspended\n",
+		(speed == USB_SPEED_HIGH) ? "high" : "non-high");

HS : FS/LS you mean?

Yes, it is what I mean.
OK, I will change to HS and FS/LS.

Quoted 4 lines
Quoted 4 lines
drivers/usb/phy/phy-mxs-usb.c +4 -0
+/*
+ * For mxs PHY, there are two PHY issues related to suspend/resume.
+ * For mx23 and mx28, both of two issues are existed.
+ * For mx6q and mx6dl, only one issue is existed.
Quoted 8 lines

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_on_disconnect(struct usb_phy *phy, · line 263

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +5 -0
+ * For mx6 sololite, none issue is existed.
+ */
+static void mxs_phy_workaround(struct mxs_phy *mxs_phy)
+{
+	if (is_mx23_phy(mxs_phy)) {

This is_mx23_phy() returns 1 for mx28 too? It's not too clear, not even from the comment above, a short comment here would help for sure.

Quoted 2 lines

mx23 and mx28 PHY are the same PHY, so the fixes are the same. Anything I need to add?

I believe it's OK. But identifying MX28 PHY via is_mx23_phy() might be a little confusing. I'm just trying to keep this driver flushed out of my brain here and do an unbiased review ;-)

Best regards,
Marek Vasut

author
#17 lore raw

PATCH 6/12 usb: phy: Add set_wakeup API

In reply to Peter Chen

This API is used to set wakeup enable at PHY registers, in that case, the PHY can be waken up from suspend due to external events, like vbus change, dp/dm change and id change.

---
 include/linux/usb/phy.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
include/linux/usb/phy.h +16 -0
index a747960..c6ebe1d 100644
@@ -111,6 +111,13 @@ struct usb_phy {
 	int	(*set_suspend)(struct usb_phy *x,
 				int suspend);
 
+	/*
+	 * Set wakeup enable for PHY, in that case, the PHY can be
+	 * waken up from suspend status due to external events,
+	 * like vbus change, dp/dm change and id.
+	 */
+	int	(*set_wakeup)(struct usb_phy *x, bool enabled);
+
 	/* notify phy connect status change */
 	int	(*notify_connect)(struct usb_phy *x,
 			enum usb_device_speed speed);
@@ -270,6 +277,15 @@ usb_phy_set_suspend(struct usb_phy *x, int suspend)
 }
 
 static inline int
+usb_phy_set_wakeup(struct usb_phy *x, bool enabled)
+{
+	if (x && x->set_wakeup)
+		return x->set_wakeup(x, enabled);
+	else
+		return 0;
+}
+
+static inline int
 usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed)
 {
 	if (x && x->notify_connect)
Signature · 1 line
1.7.1
author
#18 lore raw

PATCH 7/12 usb: phy-mxs: Add implementation of set_wakeup

In reply to Peter Chen

When we need the PHY can be waken up by external signals, we can call this API. Besides, we call mxs_phy_disconnect_line at this API to close the connection between USB PHY and controller, after that, the line state from controller is SE0. Once the PHY is out of power, without calling mxs_phy_disconnect_line, there are unknown wakeups due to dp/dm floating at device mode.

---
 drivers/usb/phy/phy-mxs-usb.c |   82 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 1 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +81 -1
index 8661dae..693f9a4 100644
@@ -31,6 +31,9 @@
 #define HW_USBPHY_CTRL_SET			0x34
 #define HW_USBPHY_CTRL_CLR			0x38
 
+#define HW_USBPHY_DEBUG_SET			0x54
+#define HW_USBPHY_DEBUG_CLR			0x58
+
 #define HW_USBPHY_IP				0x90
 #define HW_USBPHY_IP_SET			0x94
 #define HW_USBPHY_IP_CLR			0x98
@@ -39,6 +42,9 @@
 #define BM_USBPHY_CTRL_CLKGATE			BIT(30)
 #define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS	BIT(26)
 #define BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE	BIT(25)
+#define BM_USBPHY_CTRL_ENVBUSCHG_WKUP		BIT(23)
+#define BM_USBPHY_CTRL_ENIDCHG_WKUP		BIT(22)
+#define BM_USBPHY_CTRL_ENDPDMCHG_WKUP		BIT(21)
 #define BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD	BIT(20)
 #define BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE	BIT(19)
 #define BM_USBPHY_CTRL_ENAUTO_PWRON_PLL		BIT(18)
@@ -46,7 +52,20 @@
 #define BM_USBPHY_CTRL_ENUTMILEVEL2		BIT(14)
 #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	BIT(1)
 
-#define BM_USBPHY_IP_FIX                       (BIT(17) | BIT(18))
+#define BM_USBPHY_IP_FIX			(BIT(17) | BIT(18))
+
+#define BM_USBPHY_DEBUG_CLKGATE			BIT(30)
+
+/* Anatop Registers */
+#define ANADIG_USB1_VBUS_DET_STAT		0x1c0
+
+#define ANADIG_USB1_LOOPBACK_SET		0x1e4
+#define ANADIG_USB1_LOOPBACK_CLR		0x1e8
+
+#define BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID	BIT(3)
+
+#define BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1	BIT(2)
+#define BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN	BIT(5)
 
 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
 
@@ -61,6 +80,7 @@ struct mxs_phy {
 	struct clk *clk;
 	enum imx_phy_type devtype;
 	struct regmap *regmap_anatop;
+	bool disconnect_line_without_vbus_is_needed;
 };
 
 static inline int is_mx6q_phy(struct mxs_phy *data)
@@ -134,6 +154,44 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
 	return 0;
 }
 
+static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
+{
+	void __iomem *base = mxs_phy->phy.io_priv;
+	bool vbus_is_on = false;
+	static bool line_is_disconnected;
+	unsigned int vbus_value = 0;
+
+	/* Only the SoCs have anatop need below operation */
+	if (!mxs_phy->disconnect_line_without_vbus_is_needed)
+		return;
+
+	regmap_read(mxs_phy->regmap_anatop, ANADIG_USB1_VBUS_DET_STAT,
+			&vbus_value);
+	if (vbus_value & BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID)
+		vbus_is_on = true;
+
+	if (on && !vbus_is_on) {
+		writel_relaxed(BM_USBPHY_DEBUG_CLKGATE,
+			base + HW_USBPHY_DEBUG_CLR);
+		regmap_write(mxs_phy->regmap_anatop, ANADIG_USB1_LOOPBACK_SET,
+				BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1 |
+				BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN);
+		/* Delay some time, and let Linestate be SE0 for controller */
+		usleep_range(500, 1000);
+		line_is_disconnected = true;
+	} else if (line_is_disconnected) {
+		regmap_write(mxs_phy->regmap_anatop, ANADIG_USB1_LOOPBACK_CLR,
+				BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1 |
+				BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN);
+		writel_relaxed(BM_USBPHY_DEBUG_CLKGATE,
+				base + HW_USBPHY_DEBUG_SET);
+		line_is_disconnected = false;
+	}
+
+	dev_dbg(mxs_phy->phy.dev, "line is %s\n", line_is_disconnected
+			? "disconnected" : "connected");
+}
+
 static int mxs_phy_init(struct usb_phy *phy)
 {
 	struct mxs_phy *mxs_phy = to_mxs_phy(phy);
@@ -171,6 +229,23 @@ static int mxs_phy_suspend(struct usb_phy *x, int suspend)
 	return 0;
 }
 
+static int mxs_phy_set_wakeup(struct usb_phy *x, bool enabled)
+{
+	struct mxs_phy *mxs_phy = to_mxs_phy(x);
+	u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
+			BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
+				BM_USBPHY_CTRL_ENIDCHG_WKUP;
+	if (enabled) {
+		mxs_phy_disconnect_line(mxs_phy, true);
+		writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_SET);
+	} else {
+		writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_CLR);
+		mxs_phy_disconnect_line(mxs_phy, false);
+	}
+
+	return 0;
+}
+
 static int mxs_phy_on_connect(struct usb_phy *phy,
 		enum usb_device_speed speed)
 {
@@ -315,6 +390,10 @@ static int mxs_phy_probe(struct platform_device *pdev)
 		}
 	}
 
+	if (of_find_property(np, "disconnect_line_without_vbus", NULL) &&
+			mxs_phy->regmap_anatop)
+		mxs_phy->disconnect_line_without_vbus_is_needed = true;
+
 	mxs_phy->phy.io_priv		= base;
 	mxs_phy->phy.dev		= &pdev->dev;
 	mxs_phy->phy.label		= DRIVER_NAME;
@@ -324,6 +403,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	mxs_phy->phy.notify_connect	= mxs_phy_on_connect;
 	mxs_phy->phy.notify_disconnect	= mxs_phy_on_disconnect;
 	mxs_phy->phy.type		= USB_PHY_TYPE_USB2;
+	mxs_phy->phy.set_wakeup		= mxs_phy_set_wakeup;
 
 	ATOMIC_INIT_NOTIFIER_HEAD(&mxs_phy->phy.notifier);
 
Signature · 1 line
1.7.1
#19 lore raw

PATCH 7/12 usb: phy-mxs: Add implementation of set_wakeup

Dear Peter Chen,

Quoted 12 lines

When we need the PHY can be waken up by external signals, we can call this API. Besides, we call mxs_phy_disconnect_line at this API to close the connection between USB PHY and controller, after that, the line state from controller is SE0. Once the PHY is out of power, without calling mxs_phy_disconnect_line, there are unknown wakeups due to dp/dm floating at device mode.

---
 drivers/usb/phy/phy-mxs-usb.c |   82

++++++++++++++++++++++++++++++++++++++++- 1 files changed, 81 insertions(+), 1 deletions(-)

[...]

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_suspend(struct usb_phy *x, int suspend) · line 237

Quoted 6 lines
drivers/usb/phy/phy-mxs-usb.c +6 -0
+static int mxs_phy_set_wakeup(struct usb_phy *x, bool enabled)
+{
+	struct mxs_phy *mxs_phy = to_mxs_phy(x);
+	u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
+			BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
+				BM_USBPHY_CTRL_ENIDCHG_WKUP;

Does this stuff pass checkpatch at all? I mean, this alignment seems a bit strange.

Quoted 15 lines
drivers/usb/phy/phy-mxs-usb.c +11 -0
+	if (enabled) {
+		mxs_phy_disconnect_line(mxs_phy, true);
+		writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_SET);
+	} else {
+		writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_CLR);
+		mxs_phy_disconnect_line(mxs_phy, false);
+	}
+
+	return 0;
+}
+
 static int mxs_phy_on_connect(struct usb_phy *phy,
 		enum usb_device_speed speed)
 {

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_probe(struct platform_device *pdev) · line 394

Quoted 5 lines
drivers/usb/phy/phy-mxs-usb.c +2 -0
@@ -315,6 +390,10 @@ static int mxs_phy_probe(struct platform_device *pdev)
 		}
 	}
 
+	if (of_find_property(np, "disconnect_line_without_vbus", NULL) &&
+			mxs_phy->regmap_anatop)

You might want to introduce a variable here to make the condition shorter:

var = of_find....
if (var && mxs_phy->...)

Quoted 12 lines
drivers/usb/phy/phy-mxs-usb.c +3 -0
+		mxs_phy->disconnect_line_without_vbus_is_needed = true;
+
 	mxs_phy->phy.io_priv		= base;
 	mxs_phy->phy.dev		= &pdev->dev;
 	mxs_phy->phy.label		= DRIVER_NAME;
@@ -324,6 +403,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	mxs_phy->phy.notify_connect	= mxs_phy_on_connect;
 	mxs_phy->phy.notify_disconnect	= mxs_phy_on_disconnect;
 	mxs_phy->phy.type		= USB_PHY_TYPE_USB2;
+	mxs_phy->phy.set_wakeup		= mxs_phy_set_wakeup;
 
 	ATOMIC_INIT_NOTIFIER_HEAD(&mxs_phy->phy.notifier);
author
#20 lore raw

PATCH 7/12 usb: phy-mxs: Add implementation of set_wakeup

Quoted 10 lines · Marek Vasut

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_suspend(struct usb_phy *x, int suspend) · line 237

Quoted 7 lines
drivers/usb/phy/phy-mxs-usb.c +6 -0
+static int mxs_phy_set_wakeup(struct usb_phy *x, bool enabled)
+{
+	struct mxs_phy *mxs_phy = to_mxs_phy(x);
+	u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
+			BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
+				BM_USBPHY_CTRL_ENIDCHG_WKUP;

Does this stuff pass checkpatch at all? I mean, this alignment seems a bit strange.

Yes, it passed.

u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
BM_USBPHY_CTRL_ENDPDMCHG_WKUP | /* two tabs for last line */
BM_USBPHY_CTRL_ENIDCHG_WKUP; /* one tab for last line */

Any better suggestions?

Quoted 19 lines
Quoted 19 lines
drivers/usb/phy/phy-mxs-usb.c +11 -0
+	if (enabled) {
+		mxs_phy_disconnect_line(mxs_phy, true);
+		writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_SET);
+	} else {
+		writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_CLR);
+		mxs_phy_disconnect_line(mxs_phy, false);
+	}
+
+	return 0;
+}
+
 static int mxs_phy_on_connect(struct usb_phy *phy,
 		enum usb_device_speed speed)
 {
@@ -315,6 +390,10 @@ static int mxs_phy_probe(struct platform_device *pdev)
 		}
 	}
 
Quoted 7 lines

drivers/usb/phy/phy-mxs-usb.c static int mxs_phy_probe(struct platform_device *pdev) · line 394

Quoted 2 lines
drivers/usb/phy/phy-mxs-usb.c +2 -0
+	if (of_find_property(np, "disconnect_line_without_vbus", NULL) &&
+			mxs_phy->regmap_anatop)

You might want to introduce a variable here to make the condition shorter:

var = of_find....
if (var && mxs_phy->...)

I will change.

Signature · 2 lines
Best Regards,
Peter Chen
author
#21 lore raw

PATCH 8/12 usb: phy-mxs: Add system suspend/resume API

In reply to Peter Chen

We need this to keep PHY's power on or off during the system suspend mode. If we need to enable USB wakeup, then we must keep PHY's power being on during the system suspend mode. Otherwise, we need to keep PHY's power being off to save power.

---
 drivers/usb/phy/phy-mxs-usb.c |   47 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +47 -0
index 693f9a4..a91ddc0 100644
@@ -57,11 +57,18 @@
 #define BM_USBPHY_DEBUG_CLKGATE			BIT(30)
 
 /* Anatop Registers */
+#define ANADIG_ANA_MISC0			0x150
+#define ANADIG_ANA_MISC0_SET			0x154
+#define ANADIG_ANA_MISC0_CLR			0x158
+
 #define ANADIG_USB1_VBUS_DET_STAT		0x1c0
 
 #define ANADIG_USB1_LOOPBACK_SET		0x1e4
 #define ANADIG_USB1_LOOPBACK_CLR		0x1e8
 
+#define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG	BIT(12)
+#define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL BIT(11)
+
 #define BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID	BIT(3)
 
 #define BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1	BIT(2)
@@ -192,6 +199,22 @@ static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
 			? "disconnected" : "connected");
 }
 
+static void mxs_phy_enable_ldo_in_suspend(struct mxs_phy *mxs_phy, bool on)
+{
+	unsigned int reg = on ? ANADIG_ANA_MISC0_SET : ANADIG_ANA_MISC0_CLR;
+
+	/* Only the SoCs have anatop need below operation */
+	if (!mxs_phy->regmap_anatop)
+		return;
+
+	if (is_mx6q_phy(mxs_phy))
+		regmap_write(mxs_phy->regmap_anatop, reg,
+			BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG);
+	else if (is_mx6sl_phy(mxs_phy))
+		regmap_write(mxs_phy->regmap_anatop,
+			reg, BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL);
+}
+
 static int mxs_phy_init(struct usb_phy *phy)
 {
 	struct mxs_phy *mxs_phy = to_mxs_phy(phy);
@@ -413,6 +436,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, &mxs_phy->phy);
 
+	device_set_wakeup_capable(&pdev->dev, true);
 	ret = usb_add_phy_dev(&mxs_phy->phy);
 	if (ret)
 		return ret;
@@ -429,6 +453,28 @@ static int mxs_phy_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int mxs_phy_system_suspend(struct device *dev)
+{
+	struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		mxs_phy_enable_ldo_in_suspend(mxs_phy, true);
+
+	return 0;
+}
+
+static int mxs_phy_system_resume(struct device *dev)
+{
+	struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		mxs_phy_enable_ldo_in_suspend(mxs_phy, false);
+
+	return 0;
+}
+
+SIMPLE_DEV_PM_OPS(mxs_phy_pm, mxs_phy_system_suspend, mxs_phy_system_resume);
+
 static struct platform_driver mxs_phy_driver = {
 	.probe = mxs_phy_probe,
 	.remove = mxs_phy_remove,
@@ -436,6 +482,7 @@ static struct platform_driver mxs_phy_driver = {
 		.name = DRIVER_NAME,
 		.owner	= THIS_MODULE,
 		.of_match_table = mxs_phy_dt_ids,
+		.pm = &mxs_phy_pm,
 	 },
 };
 
Signature · 1 line
1.7.1
author
#22 lore raw

PATCH 9/12 usb: phy-mxs: update binding for adding anatop phandle

In reply to Peter Chen

Add anatop phandle which is used to access anatop registers to control PHY's power and other USB operations.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/usb/mxs-phy.txt +2 -0
index 5835b27..1a9bd85 100644
@@ -4,10 +4,12 @@ Required properties:
 - compatible: Should be "fsl,imx23-usbphy"
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
+- fsl,anatop: phandle for anatop register
 
 Example:
 usbphy1: usbphy at 020c9000 {
 	compatible = "fsl,imx6q-usbphy", "fsl,imx23-usbphy";
 	reg = <0x020c9000 0x1000>;
 	interrupts = <0 44 0x04>;
+	fsl,anatop = <&anatop>;
 };
Signature · 1 line
1.7.1
#23 lore raw

PATCH 9/12 usb: phy-mxs: update binding for adding anatop phandle

Quoted 13 lines · Peter Chen

Add anatop phandle which is used to access anatop registers to control PHY's power and other USB operations.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/usb/mxs-phy.txt +0 -0
index 5835b27..1a9bd85 100644

Documentation/devicetree/bindings/usb/mxs-phy.txt Required properties: · line 7

Quoted 4 lines
Documentation/devicetree/bindings/usb/mxs-phy.txt +1 -0
@@ -4,10 +4,12 @@ Required properties:
 - compatible: Should be "fsl,imx23-usbphy"
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
+- fsl,anatop: phandle for anatop register

It's only required for imx6 phy not necessarily for imx23/28 phy, right?

Shawn

Quoted 12 lines
Documentation/devicetree/bindings/usb/mxs-phy.txt +1 -0
 Example:
 usbphy1: usbphy at 020c9000 {
 	compatible = "fsl,imx6q-usbphy", "fsl,imx23-usbphy";
 	reg = <0x020c9000 0x1000>;
 	interrupts = <0 44 0x04>;
+	fsl,anatop = <&anatop>;
 };
Signature · 1 line
1.7.1
author
#24 lore raw

PATCH 9/12 usb: phy-mxs: update binding for adding anatop phandle

Quoted 9 lines · Shawn Guo
Quoted 8 lines · Peter Chen

Add anatop phandle which is used to access anatop registers to control PHY's power and other USB operations.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Quoted 12 lines

Documentation/devicetree/bindings/usb/mxs-phy.txt Required properties: · line 7

Quoted 9 lines
Documentation/devicetree/bindings/usb/mxs-phy.txt +1 -0
index 5835b27..1a9bd85 100644
@@ -4,10 +4,12 @@ Required properties:
 - compatible: Should be "fsl,imx23-usbphy"
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
+- fsl,anatop: phandle for anatop register

It's only required for imx6 phy not necessarily for imx23/28 phy, right?

Yes, I will comment it

Signature · 2 lines
Best Regards,
Peter Chen
author
#25 lore raw

PATCH 10/12 ARM: dts: imx6: add anatop phandle for usbphy

In reply to Peter Chen

Add anatop phandle for usbphy

---
 arch/arm/boot/dts/imx6qdl.dtsi |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/boot/dts/imx6qdl.dtsi +2 -0
index ef51342..145ece2 100644
@@ -541,6 +541,7 @@
 				reg = <0x020c9000 0x1000>;
 				interrupts = <0 44 0x04>;
 				clocks = <&clks 182>;
+				fsl,anatop = <&anatop>;
 			};
 
 			usbphy2: usbphy at 020ca000 {
@@ -548,6 +549,7 @@
 				reg = <0x020ca000 0x1000>;
 				interrupts = <0 45 0x04>;
 				clocks = <&clks 183>;
+				fsl,anatop = <&anatop>;
 			};
 
 			snvs at 020cc000 {
Signature · 1 line
1.7.1
author
#26 lore raw

PATCH 11/12 usb: phy-mxs: update binding for adding disconnect line property

In reply to Peter Chen

This property is used to disconnect line between USB PHY and USB controller.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/usb/mxs-phy.txt +4 -0
index 1a9bd85..099b0bb 100644
@@ -5,6 +5,9 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
 - fsl,anatop: phandle for anatop register
+- disconnect_line_without_vbus: needs to disconnect
+connection between USB PHY and controller, it can avoid
+unexpected wakeup interrupt when the PHY is out of power
 
 Example:
 usbphy1: usbphy at 020c9000 {
@@ -12,4 +15,5 @@ usbphy1: usbphy at 020c9000 {
 	reg = <0x020c9000 0x1000>;
 	interrupts = <0 44 0x04>;
 	fsl,anatop = <&anatop>;
+	disconnect_line_without_vbus;
 };
Signature · 1 line
1.7.1
#27 lore raw

PATCH 11/12 usb: phy-mxs: update binding for adding disconnect line property

Dear Peter Chen,

Quoted 14 lines

This property is used to disconnect line between USB PHY and USB controller.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/usb/mxs-phy.txt index 1a9bd85..099b0bb 100644

Documentation/devicetree/bindings/usb/mxs-phy.txt Required properties: · line 10

Quoted 6 lines
Documentation/devicetree/bindings/usb/mxs-phy.txt +3 -0
@@ -5,6 +5,9 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
 - fsl,anatop: phandle for anatop register
+- disconnect_line_without_vbus: needs to disconnect
+connection between USB PHY and controller, it can avoid
+unexpected wakeup interrupt when the PHY is out of power

Uh oh, this might needs some rewording. I didn't understand the reason for this prop before I checked the 12/12 patch.

Best regards,
Marek Vasut

author
#28 lore raw

PATCH 11/12 usb: phy-mxs: update binding for adding disconnect line property

Quoted 10 lines · Marek Vasut

Dear Peter Chen,

Quoted 8 lines

This property is used to disconnect line between USB PHY and USB controller.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Quoted 16 lines

Documentation/devicetree/bindings/usb/mxs-phy.txt Required properties: · line 10

Quoted 12 lines
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/usb/mxs-phy.txt index 1a9bd85..099b0bb 100644

Documentation/devicetree/bindings/usb/mxs-phy.txt +3 -0
@@ -5,6 +5,9 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
 - fsl,anatop: phandle for anatop register
+- disconnect_line_without_vbus: needs to disconnect
+connection between USB PHY and controller, it can avoid
+unexpected wakeup interrupt when the PHY is out of power

Uh oh, this might needs some rewording. I didn't understand the reason for this prop before I checked the 12/12 patch.

So, the better sequence like below, correct?

Binding doc patch
source code change patch
dts file patch

Signature · 2 lines
Best Regards,
Peter Chen
#29 lore raw

PATCH 11/12 usb: phy-mxs: update binding for adding disconnect line property

In reply to Peter Chen

Dear Peter Chen,

Quoted 23 lines · Peter Chen

This property is used to disconnect line between USB PHY and USB controller.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/usb/mxs-phy.txt +3 -0
index 1a9bd85..099b0bb 100644
@@ -5,6 +5,9 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
 - fsl,anatop: phandle for anatop register
+- disconnect_line_without_vbus: needs to disconnect
+connection between USB PHY and controller, it can avoid
+unexpected wakeup interrupt when the PHY is out of power
 
 Example:
 usbphy1: usbphy at 020c9000 {

Documentation/devicetree/bindings/usb/mxs-phy.txt usbphy1: usbphy at 020c9000 { · line 19

Quoted 5 lines
Documentation/devicetree/bindings/usb/mxs-phy.txt +1 -0
@@ -12,4 +15,5 @@ usbphy1: usbphy at 020c9000 {
 	reg = <0x020c9000 0x1000>;
 	interrupts = <0 44 0x04>;
 	fsl,anatop = <&anatop>;
+	disconnect_line_without_vbus;
 };

Device Tree properties use "-" as a separator, not "_". So, it should be:

disconnect-line-without-vbus

Also, all your patches touching Device Tree bindings should be Cc'ed to the devicetree@ mailing list.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
author
#30 lore raw

PATCH 11/12 usb: phy-mxs: update binding for adding disconnect line property

Quoted 35 lines · Thomas Petazzoni

Dear Peter Chen,

Quoted 23 lines · Peter Chen

This property is used to disconnect line between USB PHY and USB controller.

---
 Documentation/devicetree/bindings/usb/mxs-phy.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/usb/mxs-phy.txt +3 -0
index 1a9bd85..099b0bb 100644
@@ -5,6 +5,9 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain phy interrupt
 - fsl,anatop: phandle for anatop register
+- disconnect_line_without_vbus: needs to disconnect
+connection between USB PHY and controller, it can avoid
+unexpected wakeup interrupt when the PHY is out of power
 
 Example:
 usbphy1: usbphy at 020c9000 {

Documentation/devicetree/bindings/usb/mxs-phy.txt usbphy1: usbphy at 020c9000 { · line 19

Quoted 5 lines
Documentation/devicetree/bindings/usb/mxs-phy.txt +1 -0
@@ -12,4 +15,5 @@ usbphy1: usbphy at 020c9000 {
 	reg = <0x020c9000 0x1000>;
 	interrupts = <0 44 0x04>;
 	fsl,anatop = <&anatop>;
+	disconnect_line_without_vbus;
 };

Device Tree properties use "-" as a separator, not "_". So, it should be:

Quoted 5 lines

disconnect-line-without-vbus

Also, all your patches touching Device Tree bindings should be Cc'ed to the devicetree@ mailing list.

Thanks, I will change, and cc DT ML and maintainer, thanks.

Signature · 2 lines
Best Regards,
Peter Chen
author
#31 lore raw

PATCH 12/12 ARM: dts: imx6: Add disconnect_line_without_vbus property for usbphy

In reply to Peter Chen

When the vbus is not there and the PHY is out of power, we need to disconnect connection between USB PHY and USB controller, otherwise the unexpected USB wakeup will occur due to dp/dm change at device mode.

---
 arch/arm/boot/dts/imx6qdl.dtsi |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/boot/dts/imx6qdl.dtsi +1 -0
index 145ece2..b95ab40 100644
@@ -542,6 +542,7 @@
 				interrupts = <0 44 0x04>;
 				clocks = <&clks 182>;
 				fsl,anatop = <&anatop>;
+				disconnect_line_without_vbus;
 			};
 
 			usbphy2: usbphy at 020ca000 {
Signature · 1 line
1.7.1