linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nagarjuna Kristam <nkristam@nvidia.com>
To: <balbi@kernel.org>, <gregkh@linuxfoundation.org>,
	<thierry.reding@gmail.com>, <jonathanh@nvidia.com>,
	<mark.rutland@arm.com>, <robh+dt@kernel.org>, <kishon@ti.com>
Cc: <devicetree@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Nagarjuna Kristam <nkristam@nvidia.com>
Subject: [Patch V5 07/21] phy: tegra: xusb: Add set_mode support for UTMI phy on Tegra186
Date: Mon, 10 Feb 2020 13:41:33 +0530	[thread overview]
Message-ID: <1581322307-11140-8-git-send-email-nkristam@nvidia.com> (raw)
In-Reply-To: <1581322307-11140-1-git-send-email-nkristam@nvidia.com>

Add support for set_mode on UTMI phy. This allow XUSB host/device mode
drivers to configure the hardware to corresponding modes.

Signed-off-by: Nagarjuna Kristam <nkristam@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
---
V5:
 - No changes.
---
V4:
 - Added comment for conditional regulator disable.
 - Added Acked-by info.
---
V2-V3:
 - No changes in this version
---
 drivers/phy/tegra/xusb-tegra186.c | 114 ++++++++++++++++++++++++++++++--------
 1 file changed, 92 insertions(+), 22 deletions(-)

diff --git a/drivers/phy/tegra/xusb-tegra186.c b/drivers/phy/tegra/xusb-tegra186.c
index 84c2739..ea62251 100644
--- a/drivers/phy/tegra/xusb-tegra186.c
+++ b/drivers/phy/tegra/xusb-tegra186.c
@@ -301,6 +301,97 @@ static void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy)
 	tegra186_utmi_bias_pad_power_off(padctl);
 }
 
+static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl,
+					       bool status)
+{
+	u32 value;
+
+	dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear");
+
+	value = padctl_readl(padctl, USB2_VBUS_ID);
+
+	if (status) {
+		value |= VBUS_OVERRIDE;
+		value &= ~ID_OVERRIDE(~0);
+		value |= ID_OVERRIDE_FLOATING;
+	} else {
+		value &= ~VBUS_OVERRIDE;
+	}
+
+	padctl_writel(padctl, value, USB2_VBUS_ID);
+
+	return 0;
+}
+
+static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl,
+					    bool status)
+{
+	u32 value;
+
+	dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear");
+
+	value = padctl_readl(padctl, USB2_VBUS_ID);
+
+	if (status) {
+		if (value & VBUS_OVERRIDE) {
+			value &= ~VBUS_OVERRIDE;
+			padctl_writel(padctl, value, USB2_VBUS_ID);
+			usleep_range(1000, 2000);
+
+			value = padctl_readl(padctl, USB2_VBUS_ID);
+		}
+
+		value &= ~ID_OVERRIDE(~0);
+		value |= ID_OVERRIDE_GROUNDED;
+	} else {
+		value &= ~ID_OVERRIDE(~0);
+		value |= ID_OVERRIDE_FLOATING;
+	}
+
+	padctl_writel(padctl, value, USB2_VBUS_ID);
+
+	return 0;
+}
+
+static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode,
+				      int submode)
+{
+	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
+	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
+	struct tegra_xusb_usb2_port *port = tegra_xusb_find_usb2_port(padctl,
+								lane->index);
+	int err = 0;
+
+	mutex_lock(&padctl->lock);
+
+	dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode);
+
+	if (mode == PHY_MODE_USB_OTG) {
+		if (submode == USB_ROLE_HOST) {
+			tegra186_xusb_padctl_id_override(padctl, true);
+
+			err = regulator_enable(port->supply);
+		} else if (submode == USB_ROLE_DEVICE) {
+			tegra186_xusb_padctl_vbus_override(padctl, true);
+		} else if (submode == USB_ROLE_NONE) {
+			/*
+			 * When port is peripheral only or role transitions to
+			 * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not
+			 * enabled.
+			 */
+			if (regulator_is_enabled(port->supply))
+				regulator_disable(port->supply);
+
+			tegra186_xusb_padctl_id_override(padctl, false);
+			tegra186_xusb_padctl_vbus_override(padctl, false);
+		}
+	}
+
+	mutex_unlock(&padctl->lock);
+
+	return err;
+}
+
 static int tegra186_utmi_phy_power_on(struct phy *phy)
 {
 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
@@ -439,6 +530,7 @@ static const struct phy_ops utmi_phy_ops = {
 	.exit = tegra186_utmi_phy_exit,
 	.power_on = tegra186_utmi_phy_power_on,
 	.power_off = tegra186_utmi_phy_power_off,
+	.set_mode = tegra186_utmi_phy_set_mode,
 	.owner = THIS_MODULE,
 };
 
@@ -857,28 +949,6 @@ static void tegra186_xusb_padctl_remove(struct tegra_xusb_padctl *padctl)
 {
 }
 
-static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl,
-					       bool status)
-{
-	u32 value;
-
-	dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear");
-
-	value = padctl_readl(padctl, USB2_VBUS_ID);
-
-	if (status) {
-		value |= VBUS_OVERRIDE;
-		value &= ~ID_OVERRIDE(~0);
-		value |= ID_OVERRIDE_FLOATING;
-	} else {
-		value &= ~VBUS_OVERRIDE;
-	}
-
-	padctl_writel(padctl, value, USB2_VBUS_ID);
-
-	return 0;
-}
-
 static const struct tegra_xusb_padctl_ops tegra186_xusb_padctl_ops = {
 	.probe = tegra186_xusb_padctl_probe,
 	.remove = tegra186_xusb_padctl_remove,
-- 
2.7.4


  parent reply	other threads:[~2020-02-10  8:12 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-10  8:11 [Patch V5 00/21] Tegra XUSB OTG support Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 01/21] dt-bindings: phy: tegra-xusb: Add usb-role-switch Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 02/21] dt-bindings: usb: Add NVIDIA Tegra XUSB device mode controller binding Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 03/21] phy: tegra: xusb: Add usb-role-switch support Nagarjuna Kristam
2020-02-17  8:39   ` Thierry Reding
2020-02-10  8:11 ` [Patch V5 04/21] phy: tegra: xusb: Add usb-phy support Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 05/21] phy: tegra: xusb: Add support to get companion USB 3 port Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 06/21] phy: tegra: xusb: Add set_mode support for USB 2 phy on Tegra210 Nagarjuna Kristam
2020-02-10  8:11 ` Nagarjuna Kristam [this message]
2020-02-10  8:11 ` [Patch V5 08/21] usb: xhci-tegra: Add OTG support Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 09/21] usb: gadget: tegra-xudc: Remove usb-role-switch support Nagarjuna Kristam
2020-02-17  8:38   ` Thierry Reding
2020-02-10  8:11 ` [Patch V5 10/21] usb: gadget: tegra-xudc: Add usb-phy support Nagarjuna Kristam
2020-02-17  8:40   ` Thierry Reding
2020-02-10  8:11 ` [Patch V5 11/21] usb: gadget: tegra-xudc: use phy_set_mode to set/unset device mode Nagarjuna Kristam
2020-02-17  8:40   ` Thierry Reding
2020-02-10  8:11 ` [Patch V5 12/21] usb: gadget: tegra-xudc: support multiple device modes Nagarjuna Kristam
2020-02-17  8:42   ` Thierry Reding
2020-02-10  8:11 ` [Patch V5 13/21] arm64: tegra: update OTG port entries for jetson-tx1 Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 14/21] arm64: tegra: update OTG port entries for jetson-tx2 Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 15/21] arm64: tegra: Add xudc node for Tegra210 Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 16/21] arm64: tegra: Enable xudc on Jetson TX1 Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 17/21] arm64: tegra: Add xudc node for Tegra186 Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 18/21] arm64: tegra: Enable xudc node on Jetson TX2 Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 19/21] ARM: tegra: Remove USB 2-0 port from Jetson TK1 padctl Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 20/21] arm64: tegra: update OTG port entries for jetson-nano Nagarjuna Kristam
2020-02-10  8:11 ` [Patch V5 21/21] arm64: tegra: Enable xudc node on Jetson nano Nagarjuna Kristam
2020-02-17  8:51 ` [Patch V5 00/21] Tegra XUSB OTG support Thierry Reding
2020-02-27 17:32   ` Thierry Reding
2020-03-04  7:01     ` Greg Kroah-Hartman
2020-03-12  9:22       ` Thierry Reding
2020-03-13  4:48         ` Kishon Vijay Abraham I
2020-03-13 14:48         ` Felipe Balbi

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=1581322307-11140-8-git-send-email-nkristam@nvidia.com \
    --to=nkristam@nvidia.com \
    --cc=balbi@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonathanh@nvidia.com \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).