public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vasily Khoruzhick <anarsoul@gmail.com>
To: Simon Glass <sjg@chromium.org>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Kever Yang <kever.yang@rock-chips.com>,
	Akash Gajjar <gajjar04akash@gmail.com>,
	Manoj Sai <abbaraju.manojsai@amarulasolutions.com>,
	Jagan Teki <jagan@amarulasolutions.com>,
	John Keeping <john@metanate.com>,
	Ren Jianing <jianing.ren@rock-chips.com>,
	u-boot@lists.denx.de
Cc: Vasily Khoruzhick <anarsoul@gmail.com>
Subject: [PATCH 1/2] phy: rockchip-inno-usb2: add support for phy-supply
Date: Tue,  7 Mar 2023 11:37:47 -0800	[thread overview]
Message-ID: <20230307193748.25712-1-anarsoul@gmail.com> (raw)

PHY driver needs to enable PHY supply, otherwise port will
remain unpowered.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 59 ++++++++++++++++++-
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index 55e1dbcfef..1ef40b448e 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -19,6 +19,7 @@
 #include <asm/io.h>
 #include <linux/iopoll.h>
 #include <asm/arch-rockchip/clock.h>
+#include <power/regulator.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -62,6 +63,10 @@ struct rockchip_usb2phy {
 	void *reg_base;
 	struct clk phyclk;
 	const struct rockchip_usb2phy_cfg *phy_cfg;
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+	struct udevice *host_supply;
+	struct udevice *otg_supply;
+#endif
 };
 
 static inline int property_enable(void *reg_base,
@@ -86,12 +91,40 @@ struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy)
 	return &phy_cfg->port_cfgs[phy->id];
 }
 
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+static int rockchip_usb2phy_regulator_set_enable(struct phy *phy, bool enable)
+{
+	struct udevice *parent = dev_get_parent(phy->dev);
+	struct rockchip_usb2phy *priv = dev_get_priv(parent);
+	struct udevice *supply;
+	int ret = 0;
+	if (phy->id == USB2PHY_PORT_HOST)
+		supply = priv->host_supply;
+	else
+		supply = priv->otg_supply;
+
+	if (supply)
+		ret = regulator_set_enable(supply, enable);
+
+	return ret;
+}
+#else
+static int rockchip_usb2phy_regulator_set_enable(struct phy *phy, bool enable)
+{
+	return 0;
+}
+#endif
+
 static int rockchip_usb2phy_power_on(struct phy *phy)
 {
 	struct udevice *parent = dev_get_parent(phy->dev);
 	struct rockchip_usb2phy *priv = dev_get_priv(parent);
 	const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy);
 
+	int ret = rockchip_usb2phy_regulator_set_enable(phy, true);
+	if (ret)
+		return ret;
+
 	property_enable(priv->reg_base, &port_cfg->phy_sus, false);
 
 	/* waiting for the utmi_clk to become stable */
@@ -108,6 +141,10 @@ static int rockchip_usb2phy_power_off(struct phy *phy)
 
 	property_enable(priv->reg_base, &port_cfg->phy_sus, true);
 
+	int ret = rockchip_usb2phy_regulator_set_enable(phy, false);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
@@ -149,11 +186,29 @@ static int rockchip_usb2phy_of_xlate(struct phy *phy,
 				     struct ofnode_phandle_args *args)
 {
 	const char *name = phy->dev->name;
+	struct udevice *parent = dev_get_parent(phy->dev);
+	struct rockchip_usb2phy *priv = dev_get_priv(parent);
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+	struct udevice *supply;
+	int ret = device_get_supply_regulator(phy->dev, "phy-supply", &supply);
+	if (ret && ret != -ENOENT) {
+		pr_err("Failed to get PHY regulator\n");
+		return ret;
+	}
+#endif
 
-	if (!strcasecmp(name, "host-port"))
+	if (!strcasecmp(name, "host-port")) {
 		phy->id = USB2PHY_PORT_HOST;
-	else if (!strcasecmp(name, "otg-port"))
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+		priv->host_supply = supply;
+#endif
+	}
+	else if (!strcasecmp(name, "otg-port")) {
 		phy->id = USB2PHY_PORT_OTG;
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+		priv->otg_supply = supply;
+#endif
+	}
 	else
 		dev_err(phy->dev, "improper %s device\n", name);
 
-- 
2.39.2


             reply	other threads:[~2023-03-07 19:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 19:37 Vasily Khoruzhick [this message]
2023-03-07 19:37 ` [PATCH 2/2] arm64: dts: rk3568-u-boot: Drop combphy0 assigned-clocks/rates Vasily Khoruzhick
2023-03-07 19:53   ` Mark Kettenis
2023-03-07 20:34     ` Vasily Khoruzhick
2023-03-07 21:04       ` Mark Kettenis
2023-03-07 21:34         ` Vasily Khoruzhick
2023-03-08  0:35           ` Kever Yang

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=20230307193748.25712-1-anarsoul@gmail.com \
    --to=anarsoul@gmail.com \
    --cc=abbaraju.manojsai@amarulasolutions.com \
    --cc=gajjar04akash@gmail.com \
    --cc=jagan@amarulasolutions.com \
    --cc=jianing.ren@rock-chips.com \
    --cc=john@metanate.com \
    --cc=kever.yang@rock-chips.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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