Skip to contentSkip to conversation

net: stmmac: dwmac-rk: Fix phy regulator issues

PATCH Superseded Romain Perier 2 participants 9 messages Jan 19, 2015 – Jan 20, 2015

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover net: stmmac: dwmac-rk: Fix phy regulator issues

This series fixes few issues in dwmac-rk:

1. Voltage settings was hardcoded into the driver for the phy regulator.
The driver now uses the default voltage settings found in the devicetree, which are applied throught the regulator framework.
2. The regulator name used to power on or power off the phy was put in the devicetree variable "phy_regulator", which is not standard and added a lot of code for nothing. The driver now uses the devicetree property "phy-supply" and the corresponding functions to manipulate this regulator.

The corresponding devicetree files are also updated. As, dwmac-rk was recently pushed in the development tree, I don't care about devicetree backward compatibility issues.

Romain Perier (4):
net: stmmac: dwmac-rk: Don't set the regulator voltage for phy from
the driver
ARM: dts: Add regulator voltage settings for vcc_phy in

    rk3288-evb.dtsi

net: stmmac: dwmac-rk: Use standard devicetree property for phy
regulator
ARM: dts: Convert gmac to phy-supply in rk3288-evb-rk808.dts

 arch/arm/boot/dts/rk3288-evb-rk808.dts         |  2 +-
 arch/arm/boot/dts/rk3288-evb.dtsi              |  2 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 62 ++++++++------------------
 3 files changed, 22 insertions(+), 44 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 net: stmmac: dwmac-rk: Don't set the regulator voltage for phy from the driver

As these settings can be directly expressed from devicetree for both fixed regulators and pmic-integrated regulators, it is more standard to set them from dts and let the regulator framework use the right voltage informations when it is used in the driver.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0 -1
index 35f9b86..06e1637 100644
@@ -303,7 +303,6 @@ static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
 	} else {
 		if (enable) {
 			if (!regulator_is_enabled(ldo)) {
-				regulator_set_voltage(ldo, 3300000, 3300000);
 				ret = regulator_enable(ldo);
 				if (ret != 0)
 					dev_err(dev, "%s: fail to enable %s\n",
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 ARM: dts: Add regulator voltage settings for vcc_phy in rk3288-evb.dtsi

In reply to Romain Perier
---
 arch/arm/boot/dts/rk3288-evb.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/boot/dts/rk3288-evb.dtsi +2 -0
index 489643c..1c08eb0 100644
@@ -98,6 +98,8 @@
 		pinctrl-names = "default";
 		pinctrl-0 = <&eth_phy_pwr>;
 		regulator-name = "vcc_phy";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
 		regulator-always-on;
 		regulator-boot-on;
 	};
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/4 net: stmmac: dwmac-rk: Use standard devicetree property for phy regulator

In reply to Romain Perier

Currently, dwmac-rk uses a custom propety "phy_regulator" to get the name of the right regulator to use to power on or power off the phy. This commit converts the driver to use phy-supply devicetree property and the corresponding API, it cleans the code a bit and make it simpler to maintain.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 61 ++++++++------------------
 1 file changed, 19 insertions(+), 42 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +19 -42
index 06e1637..8a8091c 100644
@@ -32,7 +32,7 @@
 struct rk_priv_data {
 	struct platform_device *pdev;
 	int phy_iface;
-	char regulator[32];
+	struct regulator *regulator;
 
 	bool clk_enabled;
 	bool clock_input;
@@ -287,46 +287,25 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)
 
 static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
 {
-	struct regulator *ldo;
-	char *ldostr = bsp_priv->regulator;
+	struct regulator *ldo = bsp_priv->regulator;
 	int ret;
 	struct device *dev = &bsp_priv->pdev->dev;
 
-	if (!ldostr) {
-		dev_err(dev, "%s: no ldo found\n", __func__);
+	if (!ldo) {
+		dev_err(dev, "%s: no regulator found\n", __func__);
 		return -1;
 	}
 
-	ldo = regulator_get(NULL, ldostr);
-	if (!ldo) {
-		dev_err(dev, "\n%s get ldo %s failed\n", __func__, ldostr);
+	if (enable) {
+		ret = regulator_enable(ldo);
+		if (ret)
+			dev_err(dev, "%s: fail to enable phy-supply\n",
+				__func__);
 	} else {
-		if (enable) {
-			if (!regulator_is_enabled(ldo)) {
-				ret = regulator_enable(ldo);
-				if (ret != 0)
-					dev_err(dev, "%s: fail to enable %s\n",
-						__func__, ldostr);
-				else
-					dev_info(dev, "turn on ldo done.\n");
-			} else {
-				dev_warn(dev, "%s is enabled before enable",
-					 ldostr);
-			}
-		} else {
-			if (regulator_is_enabled(ldo)) {
-				ret = regulator_disable(ldo);
-				if (ret != 0)
-					dev_err(dev, "%s: fail to disable %s\n",
-						__func__, ldostr);
-				else
-					dev_info(dev, "turn off ldo done.\n");
-			} else {
-				dev_warn(dev, "%s is disabled before disable",
-					 ldostr);
-			}
-		}
-		regulator_put(ldo);
+		ret = regulator_disable(ldo);
+		if (ret)
+			dev_err(dev, "%s: fail to disable phy-supply\n",
+				__func__);
 	}
 
 	return 0;
@@ -346,14 +325,12 @@ static void *rk_gmac_setup(struct platform_device *pdev)
 
 	bsp_priv->phy_iface = of_get_phy_mode(dev->of_node);
 
-	ret = of_property_read_string(dev->of_node, "phy_regulator", &strings);
-	if (ret) {
-		dev_warn(dev, "%s: Can not read property: phy_regulator.\n",
-			 __func__);
-	} else {
-		dev_info(dev, "%s: PHY power controlled by regulator(%s).\n",
-			 __func__, strings);
-		strcpy(bsp_priv->regulator, strings);
+	bsp_priv->regulator = devm_regulator_get_optional(dev, "phy");
+	if (IS_ERR(bsp_priv->regulator)) {
+		if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_err(dev, "no regulator found\n");
+		bsp_priv->regulator = NULL;
 	}
 
 	ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);
Signature · 1 line
1.9.1
#6 lore raw

PATCH 4/4 ARM: dts: Convert gmac to phy-supply in rk3288-evb-rk808.dts

In reply to Romain Perier

This replaces the property phy_regulator by the standard devicetree property phy-supply and references the device_node vcc_phy from it.

---
 arch/arm/boot/dts/rk3288-evb-rk808.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/rk3288-evb-rk808.dts +1 -1
index 831a7aa..e1d3eeb 100644
@@ -161,7 +161,7 @@
 };
 
 &gmac {
-	phy_regulator = "vcc_phy";
+	phy-supply = <&vcc_phy>;
 	phy-mode = "rgmii";
 	clock_in_out = "input";
 	snps,reset-gpio = <&gpio4 7 0>;
Signature · 1 line
1.9.1
maintainer
#4 lore raw

Re: [PATCH v1 3/4] net: stmmac: dwmac-rk: Use standard devicetree property for phy regulator

In reply to Romain Perier

Am Montag, 19. Januar 2015, 18:08:08 schrieb Romain Perier:

Quoted 7 lines

Currently, dwmac-rk uses a custom propety "phy_regulator" to get the name of the right regulator to use to power on or power off the phy. This commit converts the driver to use phy-supply devicetree property and the corresponding API, it cleans the code a bit and make it simpler to maintain.

I don't see updated binding documentation in here.

Secondly I think patch4 which changes the property in the evb-rk808 could be in here. The change is simple enough and would keep it bisectable without needing transistional patches.

And there is the one warning down below.

Quoted 86 lines
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 61

++++++++------------------ 1 file changed, 19 insertions(+), 42 deletions(-)

(quoted diff) +0 -0

b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 06e1637..8a8091c 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +13 -34
@@ -32,7 +32,7 @@
 struct rk_priv_data {
 	struct platform_device *pdev;
 	int phy_iface;
-	char regulator[32];
+	struct regulator *regulator;
 
 	bool clk_enabled;
 	bool clock_input;
@@ -287,46 +287,25 @@ static int gmac_clk_enable(struct rk_priv_data
 *bsp_priv, bool enable)
 
 static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
 {
-	struct regulator *ldo;
-	char *ldostr = bsp_priv->regulator;
+	struct regulator *ldo = bsp_priv->regulator;
 	int ret;
 	struct device *dev = &bsp_priv->pdev->dev;
 
-	if (!ldostr) {
-		dev_err(dev, "%s: no ldo found\n", __func__);
+	if (!ldo) {
+		dev_err(dev, "%s: no regulator found\n", __func__);
 		return -1;
 	}
 
-	ldo = regulator_get(NULL, ldostr);
-	if (!ldo) {
-		dev_err(dev, "\n%s get ldo %s failed\n", __func__, ldostr);
+	if (enable) {
+		ret = regulator_enable(ldo);
+		if (ret)
+			dev_err(dev, "%s: fail to enable phy-supply\n",
+				__func__);
 	} else {
-		if (enable) {
-			if (!regulator_is_enabled(ldo)) {
-				ret = regulator_enable(ldo);
-				if (ret != 0)
-					dev_err(dev, "%s: fail to enable %s\n",
-						__func__, ldostr);
-				else
-					dev_info(dev, "turn on ldo done.\n");
-			} else {
-				dev_warn(dev, "%s is enabled before enable",
-					 ldostr);
-			}
-		} else {
-			if (regulator_is_enabled(ldo)) {
-				ret = regulator_disable(ldo);
-				if (ret != 0)
-					dev_err(dev, "%s: fail to disable %s\n",
-						__func__, ldostr);
-				else
-					dev_info(dev, "turn off ldo done.\n");
-			} else {
-				dev_warn(dev, "%s is disabled before disable",
-					 ldostr);
-			}
-		}
-		regulator_put(ldo);
+		ret = regulator_disable(ldo);
+		if (ret)
+			dev_err(dev, "%s: fail to disable phy-supply\n",
+				__func__);
 	}
 
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0 -2
 	return 0;
@@ -346,14 +325,12 @@ static void *rk_gmac_setup(struct platform_device
 *pdev)
 
 	bsp_priv->phy_iface = of_get_phy_mode(dev->of_node);
 
-	ret = of_property_read_string(dev->of_node, "phy_regulator", &strings);
-	if (ret) {

drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void *rk_gmac_setup(struct platform_device · line 332

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +4 -6
-		dev_warn(dev, "%s: Can not read property: phy_regulator.\n",
-			 __func__);
-	} else {
-		dev_info(dev, "%s: PHY power controlled by regulator(%s).\n",
-			 __func__, strings);
-		strcpy(bsp_priv->regulator, strings);
+	bsp_priv->regulator = devm_regulator_get_optional(dev, "phy");
+	if (IS_ERR(bsp_priv->regulator)) {
+		if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;

this should be return ERR_PTR(-EPROBE_DEFER) and produces a warning in its current state

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +2 -0
+		dev_err(dev, "no regulator found\n");
+		bsp_priv->regulator = NULL;
 	}
 

ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);

maintainer Reviewed-by Tested-by on the v1 series
#7 lore raw
In reply to Romain Perier

Hi Romain

Am Montag, 19. Januar 2015, 18:08:05 schrieb Romain Perier:

Quoted 10 lines

This series fixes few issues in dwmac-rk:

1. Voltage settings was hardcoded into the driver for the phy regulator. The driver now uses the default voltage settings found in the devicetree,
which are applied throught the regulator framework.
2. The regulator name used to power on or power off the phy was put in the devicetree variable "phy_regulator", which is not standard and added a lot of code for nothing. The driver now uses the devicetree property "phy-supply" and the corresponding functions to manipulate this regulator.

Quoted 3 lines

The corresponding devicetree files are also updated. As, dwmac-rk was recently pushed in the development tree, I don't care about devicetree backward compatibility issues.

This last sentence is slightly misleading :-) .

The actual fact is, that these new bindings for the rk3288 gmac have not been released with any official kernel release yet ... i.e. the will be released with 3.20 in whatever form, so we don't _need_ to care about keeping compatibility still for the next 2.5 weeks or so.

@Dave: it would be good if this series (when fixed) could still go into the 3.20 material so we don't get stuck with the non-standard regulator property.

As we'll probably need a v2 due to at the issue in patch3, could you also switch places of patch1 and 2, which would keep bisecatbility (i.e. regulator property before removing the voltage setting from the driver).

Otherwise this series:

#5 lore raw

Re: [PATCH v1 3/4] net: stmmac: dwmac-rk: Use standard devicetree property for phy regulator

In reply to Heiko Stübner

Hi,

Ok I will do these changes. However, the property "phy_regulator" was not documented in Documentation/devicetree/bindings/net/rockchip-dwmac.txt ... I can document it anyway, it has probably been forgotten.

Thanks !

2015-01-19 21:12 GMT+01:00 Heiko St?bner <[email protected]>:

Quoted 125 lines

Am Montag, 19. Januar 2015, 18:08:08 schrieb Romain Perier:

Quoted 7 lines

Currently, dwmac-rk uses a custom propety "phy_regulator" to get the name of the right regulator to use to power on or power off the phy. This commit converts the driver to use phy-supply devicetree property and the corresponding API, it cleans the code a bit and make it simpler to maintain.

I don't see updated binding documentation in here.

Secondly I think patch4 which changes the property in the evb-rk808 could be in here. The change is simple enough and would keep it bisectable without needing transistional patches.

And there is the one warning down below.

Quoted 86 lines
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 61

++++++++------------------ 1 file changed, 19 insertions(+), 42 deletions(-)

(quoted diff) +0 -0

b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 06e1637..8a8091c 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +13 -34
@@ -32,7 +32,7 @@
 struct rk_priv_data {
      struct platform_device *pdev;
      int phy_iface;
-     char regulator[32];
+     struct regulator *regulator;
 
      bool clk_enabled;
      bool clock_input;
@@ -287,46 +287,25 @@ static int gmac_clk_enable(struct rk_priv_data
 *bsp_priv, bool enable)
 
 static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
 {
-     struct regulator *ldo;
-     char *ldostr = bsp_priv->regulator;
+     struct regulator *ldo = bsp_priv->regulator;
      int ret;
      struct device *dev = &bsp_priv->pdev->dev;
 
-     if (!ldostr) {
-             dev_err(dev, "%s: no ldo found\n", __func__);
+     if (!ldo) {
+             dev_err(dev, "%s: no regulator found\n", __func__);
              return -1;
      }
 
-     ldo = regulator_get(NULL, ldostr);
-     if (!ldo) {
-             dev_err(dev, "\n%s get ldo %s failed\n", __func__, ldostr);
+     if (enable) {
+             ret = regulator_enable(ldo);
+             if (ret)
+                     dev_err(dev, "%s: fail to enable phy-supply\n",
+                             __func__);
      } else {
-             if (enable) {
-                     if (!regulator_is_enabled(ldo)) {
-                             ret = regulator_enable(ldo);
-                             if (ret != 0)
-                                     dev_err(dev, "%s: fail to enable %s\n",
-                                             __func__, ldostr);
-                             else
-                                     dev_info(dev, "turn on ldo done.\n");
-                     } else {
-                             dev_warn(dev, "%s is enabled before enable",
-                                      ldostr);
-                     }
-             } else {
-                     if (regulator_is_enabled(ldo)) {
-                             ret = regulator_disable(ldo);
-                             if (ret != 0)
-                                     dev_err(dev, "%s: fail to disable %s\n",
-                                             __func__, ldostr);
-                             else
-                                     dev_info(dev, "turn off ldo done.\n");
-                     } else {
-                             dev_warn(dev, "%s is disabled before disable",
-                                      ldostr);
-                     }
-             }
-             regulator_put(ldo);
+             ret = regulator_disable(ldo);
+             if (ret)
+                     dev_err(dev, "%s: fail to disable phy-supply\n",
+                             __func__);
      }
 
      return 0;
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0 -2
@@ -346,14 +325,12 @@ static void *rk_gmac_setup(struct platform_device
 *pdev)
 
      bsp_priv->phy_iface = of_get_phy_mode(dev->of_node);
 
-     ret = of_property_read_string(dev->of_node, "phy_regulator", &strings);
-     if (ret) {

drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void *rk_gmac_setup(struct platform_device · line 332

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +4 -6
-             dev_warn(dev, "%s: Can not read property: phy_regulator.\n",
-                      __func__);
-     } else {
-             dev_info(dev, "%s: PHY power controlled by regulator(%s).\n",
-                      __func__, strings);
-             strcpy(bsp_priv->regulator, strings);
+     bsp_priv->regulator = devm_regulator_get_optional(dev, "phy");
+     if (IS_ERR(bsp_priv->regulator)) {
+             if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER)
+                     return -EPROBE_DEFER;

this should be return ERR_PTR(-EPROBE_DEFER) and produces a warning in its current state

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +2 -0
+             dev_err(dev, "no regulator found\n");
+             bsp_priv->regulator = NULL;
      }
 
      ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);
#8 lore raw
In reply to Heiko Stübner

Hi all,

2015-01-19 21:19 GMT+01:00 Heiko St?bner <[email protected]>:

Quoted 13 lines

Hi Romain

Am Montag, 19. Januar 2015, 18:08:05 schrieb Romain Perier:

Quoted 10 lines

This series fixes few issues in dwmac-rk:

1. Voltage settings was hardcoded into the driver for the phy regulator. The driver now uses the default voltage settings found in the devicetree,
which are applied throught the regulator framework.
2. The regulator name used to power on or power off the phy was put in the devicetree variable "phy_regulator", which is not standard and added a lot of code for nothing. The driver now uses the devicetree property "phy-supply" and the corresponding functions to manipulate this regulator.

Quoted 6 lines
Quoted 3 lines

The corresponding devicetree files are also updated. As, dwmac-rk was recently pushed in the development tree, I don't care about devicetree backward compatibility issues.

This last sentence is slightly misleading :-) .

Yes, I meant that I don't need to care about it, as you explain it well below. Sorry for my misleading sentence ;) . I will fix it in my second serie.

Quoted 5 lines

The actual fact is, that these new bindings for the rk3288 gmac have not been released with any official kernel release yet ... i.e. the will be released with 3.20 in whatever form, so we don't _need_ to care about keeping compatibility still for the next 2.5 weeks or so.

Quoted 7 lines

@Dave: it would be good if this series (when fixed) could still go into the 3.20 material so we don't get stuck with the non-standard regulator property.

As we'll probably need a v2 due to at the issue in patch3, could you also switch places of patch1 and 2, which would keep bisecatbility (i.e. regulator property before removing the voltage setting from the driver).

This sentence about re-ordering patches is for Dave or for me ?

Thanks,
Romain