Skip to contentSkip to conversation

usb: phy: add usb mode for usb_phy

RFC PATCH Superseded Igor Opaniuk 3 participants 7 messages Oct 7, 2019 – Oct 8, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/3 usb: phy: add usb mode for usb_phy

From: Igor Opaniuk <[email protected]>

USB phy driver may need to know the current working mode of the controller, and can provide different settings according to host mode or device mode.

---

 include/linux/usb/phy.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
include/linux/usb/phy.h +23 -0
index e4de6bc1f69b..774941be77d7 100644
@@ -63,6 +63,13 @@ enum usb_otg_state {
 	OTG_STATE_A_VBUS_ERR,
 };
 
+/* The usb role of phy to be working with */
+enum usb_current_mode {
+	USB_MODE_NONE,
+	USB_MODE_HOST,
+	USB_MODE_DEVICE,
+};
+
 struct usb_phy;
 struct usb_otg;
 
@@ -155,6 +162,13 @@ struct usb_phy {
 	 * manually detect the charger type.
 	 */
 	enum usb_charger_type (*charger_detect)(struct usb_phy *x);
+
+	/*
+	 * Set current working mode of the USB controller
+	 * (device, host)
+	 */
+	int	(*set_mode)(struct usb_phy *x,
+			enum usb_current_mode mode);
 };
 
 /* for board-specific init logic */
@@ -213,6 +227,15 @@ usb_phy_vbus_off(struct usb_phy *x)
 	return x->set_vbus(x, false);
 }
 
+static inline int
+usb_phy_set_mode(struct usb_phy *x, enum usb_current_mode mode)
+{
+	if (!x || !x->set_mode)
+		return 0;
+
+	return x->set_mode(x, mode);
+}
+
 /* for usb host and peripheral controller drivers */
 #if IS_ENABLED(CONFIG_USB_PHY)
 extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH 2/3 usb: chipidea: set mode for usb phy driver

From: Igor Opaniuk <[email protected]>

After enters one specific role, notify usb phy driver.

---

 drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/usb/chipidea/ci.h +18 -3
index 6911aef500e9..a11d23910b12 100644
@@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
 		return -ENXIO;
 
 	ret = ci->roles[role]->start(ci);
-	if (!ret)
-		ci->role = role;
-	return ret;
+	if (ret)
+		return ret;
+
+	ci->role = role;
+
+	if (ci->usb_phy) {
+		if (role == CI_ROLE_HOST)
+			usb_phy_set_mode(ci->usb_phy,
+					USB_MODE_HOST);
+		else
+			usb_phy_set_mode(ci->usb_phy,
+					USB_MODE_DEVICE);
+	}
+
+	return 0;
 }
 
 static inline void ci_role_stop(struct ci_hdrc *ci)
@@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
 	ci->role = CI_ROLE_END;
 
 	ci->roles[role]->stop(ci);
+
+	if (ci->usb_phy)
+		usb_phy_set_mode(ci->usb_phy, USB_MODE_NONE);
 }
 
 static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
Signature · 1 line
2.17.1
#2 lore raw

Re: [RFC PATCH v1 2/3] usb: chipidea: set mode for usb phy driver

Quoted 42 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

After enters one specific role, notify usb phy driver.

---

 drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/usb/chipidea/ci.h +15 -3
index 6911aef500e9..a11d23910b12 100644
@@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
 		return -ENXIO;
 
 	ret = ci->roles[role]->start(ci);
-	if (!ret)
-		ci->role = role;
-	return ret;
+	if (ret)
+		return ret;
+
+	ci->role = role;
+
+	if (ci->usb_phy) {
+		if (role == CI_ROLE_HOST)
+			usb_phy_set_mode(ci->usb_phy,
+					USB_MODE_HOST);
+		else
+			usb_phy_set_mode(ci->usb_phy,
+					USB_MODE_DEVICE);
+	}
+
+	return 0;
 }
 
 static inline void ci_role_stop(struct ci_hdrc *ci)

drivers/usb/chipidea/ci.h static inline void ci_role_stop(struct ci_hdrc *ci) · line 310

Quoted 9 lines
drivers/usb/chipidea/ci.h +3 -0
@@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
 	ci->role = CI_ROLE_END;
 
 	ci->roles[role]->stop(ci);
+
+	if (ci->usb_phy)
+		usb_phy_set_mode(ci->usb_phy, USB_MODE_NONE);
 }
 
 static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)

Hi Igor,

Thanks for doing that.

We just find this series patch will break ARM32 multi_v7_defconfig build. You may need to fix it at next revision, see below.

CC [M] drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.o
In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
/home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:36:2: error: redeclaration of enumerator ‘USB_MODE_HOST’
USB_MODE_HOST,
^~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,

                 from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
                 from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:

/home/b29397/work/projects/usb/include/linux/usb/phy.h:69:2: note: previous definition of ‘USB_MODE_HOST’ was here
USB_MODE_HOST,
^~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
/home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:37:2: error: redeclaration of enumerator ‘USB_MODE_DEVICE’
USB_MODE_DEVICE,
^~~~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,

                 from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
                 from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:

/home/b29397/work/projects/usb/include/linux/usb/phy.h:70:2: note: previous definition of ‘USB_MODE_DEVICE’ was here
USB_MODE_DEVICE,
^~~~~~~~~~~~~~~
/home/b29397/work/projects/usb/scripts/Makefile.build:280: recipe for target 'drivers/phy/ti/phy-omap-usb2.o' failed make[4]: *** [drivers/phy/ti/phy-omap-usb2.o] Error 1
make[4]: *** Waiting for unfinished jobs....

  CC      drivers/pinctrl/qcom/pinctrl-ssbi-gpio.o
  CC      drivers/regulator/bcm590xx-regulator.o
  CC      drivers/pinctrl/qcom/pinctrl-spmi-mpp.o
  CC      drivers/pinctrl/qcom/pinctrl-ssbi-mpp.o
  CC      drivers/rpmsg/imx_rpmsg.o
  CC [M]  drivers/rpmsg/rpmsg_core.o
  CC      drivers/regulator/da9210-regulator.o
  CC      drivers/gpu/drm/drm_crtc_helper.o
  CC      drivers/pinctrl/samsung/pinctrl-exynos.o
  CC      drivers/gpu/drm/drm_dp_helper.o

/home/b29397/work/projects/usb/scripts/Makefile.build:497: recipe for target 'drivers/phy/ti' failed make[3]: *** [drivers/phy/ti] Error 2

Signature · 2 lines
Thanks,
Peter Chen
#3 lore raw

Re: [RFC PATCH v1 2/3] usb: chipidea: set mode for usb phy driver

Hi Peter,

Quoted 95 lines · Peter Chen
Quoted 41 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

After enters one specific role, notify usb phy driver.

---

 drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/usb/chipidea/ci.h +15 -3
index 6911aef500e9..a11d23910b12 100644
@@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
              return -ENXIO;
 
      ret = ci->roles[role]->start(ci);
-     if (!ret)
-             ci->role = role;
-     return ret;
+     if (ret)
+             return ret;
+
+     ci->role = role;
+
+     if (ci->usb_phy) {
+             if (role == CI_ROLE_HOST)
+                     usb_phy_set_mode(ci->usb_phy,
+                                     USB_MODE_HOST);
+             else
+                     usb_phy_set_mode(ci->usb_phy,
+                                     USB_MODE_DEVICE);
+     }
+
+     return 0;
 }
 
 static inline void ci_role_stop(struct ci_hdrc *ci)

drivers/usb/chipidea/ci.h static inline void ci_role_stop(struct ci_hdrc *ci)

Quoted 10 lines
drivers/usb/chipidea/ci.h +3 -1
@@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
      ci->role = CI_ROLE_END;
 
      ci->roles[role]->stop(ci);
+
+     if (ci->usb_phy)
+             usb_phy_set_mode(ci->usb_phy, USB_MODE_NONE);
 }
 
 static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
--

Hi Igor,

Thanks for doing that.

We just find this series patch will break ARM32 multi_v7_defconfig build. You may need to fix it at next revision, see below.

CC [M] drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.o
In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
/home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:36:2: error: redeclaration of enumerator ‘USB_MODE_HOST’
USB_MODE_HOST,
^~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,

                 from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
                 from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:

/home/b29397/work/projects/usb/include/linux/usb/phy.h:69:2: note: previous definition of ‘USB_MODE_HOST’ was here
USB_MODE_HOST,
^~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
/home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:37:2: error: redeclaration of enumerator ‘USB_MODE_DEVICE’
USB_MODE_DEVICE,
^~~~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,

                 from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
                 from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:

/home/b29397/work/projects/usb/include/linux/usb/phy.h:70:2: note: previous definition of ‘USB_MODE_DEVICE’ was here
USB_MODE_DEVICE,
^~~~~~~~~~~~~~~
/home/b29397/work/projects/usb/scripts/Makefile.build:280: recipe for target 'drivers/phy/ti/phy-omap-usb2.o' failed make[4]: *** [drivers/phy/ti/phy-omap-usb2.o] Error 1
make[4]: *** Waiting for unfinished jobs....

  CC      drivers/pinctrl/qcom/pinctrl-ssbi-gpio.o
  CC      drivers/regulator/bcm590xx-regulator.o
  CC      drivers/pinctrl/qcom/pinctrl-spmi-mpp.o
  CC      drivers/pinctrl/qcom/pinctrl-ssbi-mpp.o
  CC      drivers/rpmsg/imx_rpmsg.o
  CC [M]  drivers/rpmsg/rpmsg_core.o
  CC      drivers/regulator/da9210-regulator.o
  CC      drivers/gpu/drm/drm_crtc_helper.o
  CC      drivers/pinctrl/samsung/pinctrl-exynos.o
  CC      drivers/gpu/drm/drm_dp_helper.o
Quoted 7 lines

/home/b29397/work/projects/usb/scripts/Makefile.build:497: recipe for target 'drivers/phy/ti' failed make[3]: *** [drivers/phy/ti] Error 2

--

Thanks,
Peter Chen

Seems familiar to me, AFAIK we already fixed that in our downstream kernel, will add the fix for v1.

Thanks!

--
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: [email protected]
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk

#4 lore raw

RFC PATCH 3/3 usb: phy: mxs: optimize disconnect line condition

In reply to Igor Opaniuk

From: Igor Opaniuk <[email protected]>

We only have below cases to disconnect line when suspend:
1. Device mode without connection to any host/charger(no vbus).
2. Device mode connect to a charger, usb suspend when system is entering suspend.

This patch can fix cases, when usb phy wrongly does disconnect line in case usb host enters suspend but vbus is off.

---

 drivers/usb/phy/phy-mxs-usb.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/usb/phy/phy-mxs-usb.c +16 -12
index 70b8c8248caf..d996666e09e6 100644
@@ -204,6 +204,7 @@ struct mxs_phy {
 	int port_id;
 	u32 tx_reg_set;
 	u32 tx_reg_mask;
+	enum usb_current_mode mode;
 };
 
 static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy)
@@ -386,17 +387,6 @@ static void __mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool disconnect)
 		usleep_range(500, 1000);
 }
 
-static bool mxs_phy_is_otg_host(struct mxs_phy *mxs_phy)
-{
-	void __iomem *base = mxs_phy->phy.io_priv;
-	u32 phyctrl = readl(base + HW_USBPHY_CTRL);
-
-	if (IS_ENABLED(CONFIG_USB_OTG) &&
-			!(phyctrl & BM_USBPHY_CTRL_OTG_ID_VALUE))
-		return true;
-
-	return false;
-}
 
 static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
 {
@@ -412,13 +402,26 @@ static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
 
 	vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
 
-	if (on && !vbus_is_on && !mxs_phy_is_otg_host(mxs_phy))
+	if (on && ((!vbus_is_on && mxs_phy->mode != USB_MODE_HOST)))
 		__mxs_phy_disconnect_line(mxs_phy, true);
 	else
 		__mxs_phy_disconnect_line(mxs_phy, false);
 
 }
 
+/*
+ * Set the usb current role for phy.
+ */
+static int mxs_phy_set_mode(struct usb_phy *phy,
+		enum usb_current_mode mode)
+{
+	struct mxs_phy *mxs_phy = to_mxs_phy(phy);
+
+	mxs_phy->mode = mode;
+
+	return 0;
+}
+
 static int mxs_phy_init(struct usb_phy *phy)
 {
 	int ret;
@@ -796,6 +799,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
 	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;
+	mxs_phy->phy.set_mode		= mxs_phy_set_mode;
 	mxs_phy->phy.charger_detect	= mxs_phy_charger_detect;
 
 	mxs_phy->clk = clk;
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer
#5 lore raw

Re: [RFC PATCH v1 3/3] usb: phy: mxs: optimize disconnect line condition

Hi Igor,

Quoted 8 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

We only have below cases to disconnect line when suspend:
1. Device mode without connection to any host/charger(no vbus).
2. Device mode connect to a charger, usb suspend when system is entering suspend.

Quoted 5 lines

This patch can fix cases, when usb phy wrongly does disconnect line in case usb host enters suspend but vbus is off.

Who is the original author of this patch, is it you or Li Jun?

If it is Li Jun, then his name should appear in the From field.

Also, it seems a Fixes tag is needed here.

#6 lore raw

Re: [RFC PATCH v1 3/3] usb: phy: mxs: optimize disconnect line condition

HI Fabio,

Quoted 15 lines · Fabio Estevam

Hi Igor,

Quoted 11 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

We only have below cases to disconnect line when suspend:
1. Device mode without connection to any host/charger(no vbus).
2. Device mode connect to a charger, usb suspend when system is entering suspend.

This patch can fix cases, when usb phy wrongly does disconnect line in case usb host enters suspend but vbus is off.

Quoted 6 lines
Quoted 2 lines

Who is the original author of this patch, is it you or Li Jun?

If it is Li Jun, then his name should appear in the From field.

right, it's Li Jun, will fix in v1.

Quoted 2 lines

Also, it seems a Fixes tag is needed here.

right, will do.

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: [email protected]
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk