linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] usb: phy: add usb mode for usb_phy
@ 2019-10-10 13:56 Igor Opaniuk
  2019-10-10 13:56 ` [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver Igor Opaniuk
  2019-10-10 13:56 ` [PATCH v2 3/3] usb: phy: mxs: optimize disconnect line condition Igor Opaniuk
  0 siblings, 2 replies; 4+ messages in thread
From: Igor Opaniuk @ 2019-10-10 13:56 UTC (permalink / raw)
  To: linux-usb
  Cc: Marcel Ziswiler, Philippe Schenker, Stefan Agner,
	Max Krummenacher, Oleksandr Suvorov, Li Jun, Igor Opaniuk,
	Greg Kroah-Hartman, linux-kernel

From: Li Jun <jun.li@nxp.com>

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.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
---

v2:
- restored original commit author
- fixed build for multi_v7

 include/linux/usb/phy.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index e4de6bc1f69b..d138703e3688 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -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_CURRENT_MODE_NONE,
+	USB_CURRENT_MODE_HOST,
+	USB_CURRENT_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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver
  2019-10-10 13:56 [PATCH v2 1/3] usb: phy: add usb mode for usb_phy Igor Opaniuk
@ 2019-10-10 13:56 ` Igor Opaniuk
  2019-10-11  5:50   ` Peter Chen
  2019-10-10 13:56 ` [PATCH v2 3/3] usb: phy: mxs: optimize disconnect line condition Igor Opaniuk
  1 sibling, 1 reply; 4+ messages in thread
From: Igor Opaniuk @ 2019-10-10 13:56 UTC (permalink / raw)
  To: linux-usb
  Cc: Marcel Ziswiler, Philippe Schenker, Stefan Agner,
	Max Krummenacher, Oleksandr Suvorov, Li Jun, Igor Opaniuk,
	Greg Kroah-Hartman, Peter Chen, linux-kernel

From: Li Jun <jun.li@nxp.com>

After enters one specific role, notify usb phy driver.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
---

v2:
- restored original commit author
- fixed build for multi_v7

 drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 6911aef500e9..cf9cc9402826 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -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_CURRENT_MODE_HOST);
+		else
+			usb_phy_set_mode(ci->usb_phy,
+					USB_CURRENT_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_CURRENT_MODE_NONE);
 }
 
 static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] usb: phy: mxs: optimize disconnect line condition
  2019-10-10 13:56 [PATCH v2 1/3] usb: phy: add usb mode for usb_phy Igor Opaniuk
  2019-10-10 13:56 ` [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver Igor Opaniuk
@ 2019-10-10 13:56 ` Igor Opaniuk
  1 sibling, 0 replies; 4+ messages in thread
From: Igor Opaniuk @ 2019-10-10 13:56 UTC (permalink / raw)
  To: linux-usb
  Cc: Marcel Ziswiler, Philippe Schenker, Stefan Agner,
	Max Krummenacher, Oleksandr Suvorov, Li Jun, Igor Opaniuk,
	Fabio Estevam, Felipe Balbi, Greg Kroah-Hartman, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo,
	linux-arm-kernel, linux-kernel

From: Li Jun <jun.li@nxp.com>

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.

Fixes: 7b09e67639("usb: phy: mxs: refine mxs_phy_disconnect_line")
Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
---

v2:
- restored original commit author
- fixed build for multi_v7

 drivers/usb/phy/phy-mxs-usb.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c
index 70b8c8248caf..f58ea923c7eb 100644
--- a/drivers/usb/phy/phy-mxs-usb.c
+++ b/drivers/usb/phy/phy-mxs-usb.c
@@ -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_CURRENT_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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver
  2019-10-10 13:56 ` [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver Igor Opaniuk
@ 2019-10-11  5:50   ` Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2019-10-11  5:50 UTC (permalink / raw)
  To: Igor Opaniuk
  Cc: linux-usb, Marcel Ziswiler, Philippe Schenker, Stefan Agner,
	Max Krummenacher, Oleksandr Suvorov, Jun Li, Igor Opaniuk,
	Greg Kroah-Hartman, linux-kernel

On 19-10-10 16:56:55, Igor Opaniuk wrote:
> From: Li Jun <jun.li@nxp.com>
> 
> After enters one specific role, notify usb phy driver.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
> ---
> 
> v2:
> - restored original commit author
> - fixed build for multi_v7
> 
>  drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> index 6911aef500e9..cf9cc9402826 100644
> --- a/drivers/usb/chipidea/ci.h
> +++ b/drivers/usb/chipidea/ci.h
> @@ -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_CURRENT_MODE_HOST);
> +		else
> +			usb_phy_set_mode(ci->usb_phy,
> +					USB_CURRENT_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_CURRENT_MODE_NONE);
>  }
>  
>  static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
> -- 

For chipidea part:

Acked-by: Peter Chen <peter.chen@nxp.com>

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-11  5:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 13:56 [PATCH v2 1/3] usb: phy: add usb mode for usb_phy Igor Opaniuk
2019-10-10 13:56 ` [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver Igor Opaniuk
2019-10-11  5:50   ` Peter Chen
2019-10-10 13:56 ` [PATCH v2 3/3] usb: phy: mxs: optimize disconnect line condition Igor Opaniuk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).