Linux USB
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: Peter.Chen@nxp.com, gregkh@linuxfoundation.org,
	shawnguo@kernel.org, linux-imx@nxp.com,
	stern@rowland.harvard.edu, jun.li@freescale.com
Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	kernel@pengutronix.de
Subject: [PATCH 2/3] Partially Revert "usb: chipidea: host: turn on vbus before add hcd if early vbus on is required"
Date: Thu, 27 Feb 2020 11:42:11 +0100	[thread overview]
Message-ID: <20200227104212.12562-3-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20200227104212.12562-1-m.felsch@pengutronix.de>

Commit 659459174188 ("usb: chipidea: host: turn on vbus before add hcd if
early vbus on is required") enabled the vbus regulator but didn't assign
the reg_vbus. So the vbus regulator can't be disabled anymore.

Since the port_power() callback is executed exclusive (without enabling
the port power (PP) bit) we can do the special handling within the
callback without the need of a special flag.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/usb/chipidea/host.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 48e4a5ca1835..f1832847a023 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -37,6 +37,8 @@ static int ehci_ci_portpower(struct usb_hcd *hcd, int portnum, bool enable)
 	struct ci_hdrc *ci = dev_get_drvdata(dev);
 	int ret = 0;
 	int port = HCS_N_PORTS(ehci->hcs_params);
+	u32 __iomem *status_reg = &ehci->regs->port_status[portnum];
+	u32 temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS;
 
 	if (priv->reg_vbus && enable != priv->enabled) {
 		if (port > 1) {
@@ -57,6 +59,11 @@ static int ehci_ci_portpower(struct usb_hcd *hcd, int portnum, bool enable)
 		priv->enabled = enable;
 	}
 
+	if (enable)
+		ehci_writel(ehci, temp | PORT_POWER, status_reg);
+	else
+		ehci_writel(ehci, temp & ~PORT_POWER, status_reg);
+
 	if (enable && (ci->platdata->phy_mode == USBPHY_INTERFACE_MODE_HSIC)) {
 		/*
 		 * Marvell 28nm HSIC PHY requires forcing the port to HS mode.
@@ -142,19 +149,8 @@ static int host_start(struct ci_hdrc *ci)
 	priv = (struct ehci_ci_priv *)ehci->priv;
 	priv->reg_vbus = NULL;
 
-	if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) {
-		if (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON) {
-			ret = regulator_enable(ci->platdata->reg_vbus);
-			if (ret) {
-				dev_err(ci->dev,
-				"Failed to enable vbus regulator, ret=%d\n",
-									ret);
-				goto put_hcd;
-			}
-		} else {
-			priv->reg_vbus = ci->platdata->reg_vbus;
-		}
-	}
+	if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci))
+		priv->reg_vbus = ci->platdata->reg_vbus;
 
 	if (ci->platdata->pins_host)
 		pinctrl_select_state(ci->platdata->pctl,
@@ -162,7 +158,7 @@ static int host_start(struct ci_hdrc *ci)
 
 	ret = usb_add_hcd(hcd, 0, 0);
 	if (ret) {
-		goto disable_reg;
+		goto put_hcd;
 	} else {
 		struct usb_otg *otg = &ci->otg;
 
@@ -181,10 +177,6 @@ static int host_start(struct ci_hdrc *ci)
 
 	return ret;
 
-disable_reg:
-	if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
-			(ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON))
-		regulator_disable(ci->platdata->reg_vbus);
 put_hcd:
 	usb_put_hcd(hcd);
 
@@ -203,9 +195,6 @@ static void host_stop(struct ci_hdrc *ci)
 		ci->role = CI_ROLE_END;
 		synchronize_irq(ci->irq);
 		usb_put_hcd(hcd);
-		if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
-			(ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON))
-				regulator_disable(ci->platdata->reg_vbus);
 	}
 	ci->hcd = NULL;
 	ci->otg.host = NULL;
-- 
2.20.1


  parent reply	other threads:[~2020-02-27 10:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 10:42 [PATCH 0/3] USB IMX Chipidea fix gpio vbus control Marco Felsch
2020-02-27 10:42 ` [PATCH 1/3] USB: ehci-hub: let port_power() override the ehci_port_power() Marco Felsch
2020-02-27 10:42 ` Marco Felsch [this message]
2020-02-27 10:42 ` [PATCH 3/3] Revert "usb: chipidea: add a flag for turn on vbus early for host" Marco Felsch
2020-02-27 11:18 ` [PATCH 0/3] USB IMX Chipidea fix gpio vbus control Peter Chen
2020-02-27 11:35   ` Marco Felsch
2020-02-27 12:20     ` Peter Chen
2020-02-27 12:44       ` Marco Felsch
2020-02-27 13:30         ` Peter Chen
2020-02-27 13:59           ` Peter Chen
2020-02-27 14:39           ` Marco Felsch
2020-02-28  2:51             ` Peter Chen
2020-02-28  7:48               ` Marco Felsch
2020-02-28  9:40                 ` Peter Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200227104212.12562-3-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=Peter.Chen@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jun.li@freescale.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox