Skip to contentSkip to conversation

phy: rockchip-inno-usb2: add support for phy-supply

PATCH In review Vasily Khoruzhick 2 participants 9 messages Mar 7, 2023 – Mar 8, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 phy: rockchip-inno-usb2: add support for phy-supply

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

---
v2: address check_patch.pl issues

 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 64 ++++++++++++++++++-
 1 file changed, 61 insertions(+), 3 deletions(-)
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +61 -3
index 55e1dbcfef..a859cd6f18 100644
@@ -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 IS_ENABLED(CONFIG_DM_REGULATOR)
+	struct udevice *host_supply;
+	struct udevice *otg_supply;
+#endif
 };
 
 static inline int property_enable(void *reg_base,
@@ -86,12 +91,42 @@ struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy)
 	return &phy_cfg->port_cfgs[phy->id];
 }
 
+#if IS_ENABLED(CONFIG_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 +143,11 @@ 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,13 +189,31 @@ 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 IS_ENABLED(CONFIG_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 IS_ENABLED(CONFIG_DM_REGULATOR)
+		priv->host_supply = supply;
+#endif
+	} else if (!strcasecmp(name, "otg-port")) {
 		phy->id = USB2PHY_PORT_OTG;
-	else
+#if IS_ENABLED(CONFIG_DM_REGULATOR)
+		priv->otg_supply = supply;
+#endif
+	} else {
 		dev_err(phy->dev, "improper %s device\n", name);
+	}
 
 	return 0;
 }
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 2/3 clk: rockchip: rk3568: add stubs for CLK_PCIEPHY_REF clocks

Device tree contains assigned-clock-rates property for these, but default value will work just fine

---
v2: implement stubs for CLK_PCIEPHY_REF instead of dropping assigned-clock properties

 drivers/clk/rockchip/clk_rk3568.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/rockchip/clk_rk3568.c +3 -0
index 253b69504f..1c6adc56f9 100644
@@ -425,6 +425,9 @@ static ulong rk3568_pmuclk_set_rate(struct clk *clk, ulong rate)
 	case PCLK_PMU:
 		ret = rk3568_pmu_set_pmuclk(priv, rate);
 		break;
+	case CLK_PCIEPHY0_REF:
+	case CLK_PCIEPHY1_REF:
+		return 0;
 	default:
 		return -ENOENT;
 	}
Signature · 1 line
2.39.2
Reviewed-by on v2 2/3
#2 lore raw

Re: [PATCH v2 2/3] clk: rockchip: rk3568: add stubs for CLK_PCIEPHY_REF clocks

Quoted 4 lines · Vasily Khoruzhick

Device tree contains assigned-clock-rates property for these, but default value will work just fine

Thanks,
- Kever

Quoted 21 lines

---
v2: implement stubs for CLK_PCIEPHY_REF instead of dropping assigned-clock properties

  drivers/clk/rockchip/clk_rk3568.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/clk/rockchip/clk_rk3568.c +3 -0
index 253b69504f..1c6adc56f9 100644
@@ -425,6 +425,9 @@ static ulong rk3568_pmuclk_set_rate(struct clk *clk, ulong rate)
  	case PCLK_PMU:
  		ret = rk3568_pmu_set_pmuclk(priv, rate);
  		break;
+	case CLK_PCIEPHY0_REF:
+	case CLK_PCIEPHY1_REF:
+		return 0;
  	default:
  		return -ENOENT;
  	}
#3 lore raw

PATCH v2 3/3 Revert "arm64: dts: rk356x-u-boot: Drop combphy1 assigned-clocks/rates"

In reply to Vasily Khoruzhick

This reverts commit 5bec4b0de7851a254fb4447b3599a60f95550141.

---
v2: revert dropping assigned-clock properties because we have stubs for CLK_PCIEPHY_REF clocks now

 arch/arm/dts/rk356x-u-boot.dtsi | 5 -----
 1 file changed, 5 deletions(-)
arch/arm/dts/rk356x-u-boot.dtsi +0 -5
index 2331641049..1709604b22 100644
@@ -34,11 +34,6 @@
 	};
 };
 
-&combphy1 {
-	/delete-property/ assigned-clocks;
-	/delete-property/ assigned-clock-rates;
-};
-
 &cru {
 	u-boot,dm-pre-reloc;
 	status = "okay";
Signature · 1 line
2.39.2
#4 lore raw

Re: [PATCH v2 3/3] Revert "arm64: dts: rk356x-u-boot: Drop combphy1 assigned-clocks/rates"

Hi Vasily,

    Please use a new patch instead of a revert, I think I merge the patch twice by mistake, so there is another one need to remove.

Thanks,

- Kever

Quoted 26 lines · Vasily Khoruzhick

This reverts commit 5bec4b0de7851a254fb4447b3599a60f95550141.

---
v2: revert dropping assigned-clock properties because we have stubs for CLK_PCIEPHY_REF clocks now

  arch/arm/dts/rk356x-u-boot.dtsi | 5 -----
  1 file changed, 5 deletions(-)
arch/arm/dts/rk356x-u-boot.dtsi +0 -5
index 2331641049..1709604b22 100644
@@ -34,11 +34,6 @@
  	};
  };
 
-&combphy1 {
-	/delete-property/ assigned-clocks;
-	/delete-property/ assigned-clock-rates;
-};
-
  &cru {
  	u-boot,dm-pre-reloc;
  	status = "okay";
#5 lore raw

Re: [PATCH v2 3/3] Revert "arm64: dts: rk356x-u-boot: Drop combphy1 assigned-clocks/rates"

Quoted 2 lines · Kever Yang

Hi Vasily,

Hi Kever,

Quoted 2 lines

Please use a new patch instead of a revert, I think I merge the
patch twice by mistake, so there is another one need to remove.

Sure, I changed the patch subject and description in v3.

Regards,
Vasily

Reviewed-by on v2 1/3
#6 lore raw
In reply to Vasily Khoruzhick
Quoted 4 lines · Vasily Khoruzhick

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

Thanks,
- Kever

Quoted 119 lines

---
v2: address check_patch.pl issues

  drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 64 ++++++++++++++++++-
  1 file changed, 61 insertions(+), 3 deletions(-)
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +61 -3
index 55e1dbcfef..a859cd6f18 100644
@@ -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 IS_ENABLED(CONFIG_DM_REGULATOR)
+	struct udevice *host_supply;
+	struct udevice *otg_supply;
+#endif
  };
 
  static inline int property_enable(void *reg_base,
@@ -86,12 +91,42 @@ struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy)
  	return &phy_cfg->port_cfgs[phy->id];
  }
 
+#if IS_ENABLED(CONFIG_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 +143,11 @@ 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,13 +189,31 @@ 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 IS_ENABLED(CONFIG_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 IS_ENABLED(CONFIG_DM_REGULATOR)
+		priv->host_supply = supply;
+#endif
+	} else if (!strcasecmp(name, "otg-port")) {
  		phy->id = USB2PHY_PORT_OTG;
-	else
+#if IS_ENABLED(CONFIG_DM_REGULATOR)
+		priv->otg_supply = supply;
+#endif
+	} else {
  		dev_err(phy->dev, "improper %s device\n", name);
+	}
 
  	return 0;
  }
#7 lore raw
In reply to Vasily Khoruzhick

Hi Vasily,

    This patch is cover by patch[1] from Eugen, right?

Thanks,

- Kever

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Quoted 123 lines · Vasily Khoruzhick

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

---
v2: address check_patch.pl issues

  drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 64 ++++++++++++++++++-
  1 file changed, 61 insertions(+), 3 deletions(-)
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +61 -3
index 55e1dbcfef..a859cd6f18 100644
@@ -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 IS_ENABLED(CONFIG_DM_REGULATOR)
+	struct udevice *host_supply;
+	struct udevice *otg_supply;
+#endif
  };
 
  static inline int property_enable(void *reg_base,
@@ -86,12 +91,42 @@ struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy)
  	return &phy_cfg->port_cfgs[phy->id];
  }
 
+#if IS_ENABLED(CONFIG_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 +143,11 @@ 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,13 +189,31 @@ 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 IS_ENABLED(CONFIG_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 IS_ENABLED(CONFIG_DM_REGULATOR)
+		priv->host_supply = supply;
+#endif
+	} else if (!strcasecmp(name, "otg-port")) {
  		phy->id = USB2PHY_PORT_OTG;
-	else
+#if IS_ENABLED(CONFIG_DM_REGULATOR)
+		priv->otg_supply = supply;
+#endif
+	} else {
  		dev_err(phy->dev, "improper %s device\n", name);
+	}
 
  	return 0;
  }
#8 lore raw
Quoted 2 lines · Kever Yang

Hi Vasily,

Hi Keven,

Quoted 1 line

This patch is cover by patch[1] from Eugen, right?

Yeah, I didn't notice Eugen's patch. Anyway, he sent his patch earlier, so please discard mine.

Regards,
Vasily