linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 1/2] dt-bindings: net: snps,dwmac: add phy-supply support
@ 2023-07-18 13:20 Marco Felsch
  2023-07-18 13:20 ` [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply Marco Felsch
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Felsch @ 2023-07-18 13:20 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32
  Cc: devicetree, netdev, linux-kernel, kernel, linux-stm32, linux-arm-kernel

Document the common phy-supply property to be able to specify a phy
regulator.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 Documentation/devicetree/bindings/net/snps,dwmac.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml
index 363b3e3ea3a60..f66d1839cf561 100644
--- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml
+++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml
@@ -159,6 +159,9 @@ properties:
       can be passive (no SW requirement), and requires that the MAC operate
       in a different mode than the PHY in order to function.
 
+  phy-supply:
+    description: PHY regulator
+
   snps,axi-config:
     $ref: /schemas/types.yaml#/definitions/phandle
     description:
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply
  2023-07-18 13:20 [PATCH net-next v2 1/2] dt-bindings: net: snps,dwmac: add phy-supply support Marco Felsch
@ 2023-07-18 13:20 ` Marco Felsch
  2023-07-20  4:12   ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Felsch @ 2023-07-18 13:20 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32
  Cc: devicetree, netdev, linux-kernel, kernel, linux-stm32, linux-arm-kernel

Add generic phy-supply handling support to control the phy regulator to
avoid handling it within the glue code. Use the generic stmmac_platform
code to register a possible phy-supply and the stmmac_main code to
handle the power on/off.

Changelog
---

v2:
- adapt stmmac_phy_power
- move power-on/off into stmmac_main to handle WOL
- adapt commit message

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 58 ++++++++++++++++++-
 .../ethernet/stmicro/stmmac/stmmac_platform.c | 10 ++++
 include/linux/stmmac.h                        |  1 +
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 0fca81507a779..c3700316fed6c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -31,6 +31,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/prefetch.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/regulator/consumer.h>
 #ifdef CONFIG_DEBUG_FS
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
@@ -1123,6 +1124,55 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
 	}
 }
 
+/**
+ * stmmac_phy_power - PHY regulator on/off
+ * @priv: driver private structure
+ * @enable: turn on the regulator if true else turn it off
+ * Enable or disable the regulator powering the PHY.
+ */
+static int stmmac_phy_power(struct stmmac_priv *priv, bool enable)
+{
+	struct regulator *regulator = priv->plat->phy_regulator;
+	struct device *dev = priv->device;
+
+	if (!regulator)
+		return 0;
+
+	if (enable) {
+		int ret;
+
+		ret = regulator_enable(regulator);
+		if (ret)
+			dev_err(dev, "Fail to enable regulator\n");
+
+		return ret;
+	}
+
+	regulator_disable(regulator);
+
+	return 0;
+}
+
+/**
+ * stmmac_phy_power_on - PHY regulator on
+ * @priv: driver private structure
+ * Enable the PHY regulator
+ */
+static int stmmac_phy_power_on(struct stmmac_priv *priv)
+{
+	return stmmac_phy_power(priv, true);
+}
+
+/**
+ * stmmac_phy_power_off - PHY regulator off
+ * @priv: driver private structure
+ * Disable the PHY regulator
+ */
+static void stmmac_phy_power_off(struct stmmac_priv *priv)
+{
+	stmmac_phy_power(priv, false);
+}
+
 /**
  * stmmac_init_phy - PHY initialization
  * @dev: net device structure
@@ -1248,7 +1298,8 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
 		return PTR_ERR(phylink);
 
 	priv->phylink = phylink;
-	return 0;
+
+	return stmmac_phy_power_on(priv);
 }
 
 static void stmmac_display_rx_rings(struct stmmac_priv *priv,
@@ -7469,6 +7520,7 @@ void stmmac_dvr_remove(struct device *dev)
 	if (priv->hw->pcs != STMMAC_PCS_TBI &&
 	    priv->hw->pcs != STMMAC_PCS_RTBI)
 		stmmac_mdio_unregister(ndev);
+	stmmac_phy_power_off(priv);
 	destroy_workqueue(priv->wq);
 	mutex_destroy(&priv->lock);
 	bitmap_free(priv->af_xdp_zc_qps);
@@ -7532,6 +7584,8 @@ int stmmac_suspend(struct device *dev)
 		if (device_may_wakeup(priv->device))
 			phylink_speed_down(priv->phylink, false);
 		phylink_suspend(priv->phylink, false);
+		if (!priv->plat->use_phy_wol)
+			stmmac_phy_power_off(priv);
 	}
 	rtnl_unlock();
 
@@ -7614,6 +7668,8 @@ int stmmac_resume(struct device *dev)
 		priv->irq_wake = 0;
 	} else {
 		pinctrl_pm_select_default_state(priv->device);
+		if (!priv->plat->use_phy_wol)
+			stmmac_phy_power_on(priv);
 		/* reset the phy so that it's ready */
 		if (priv->mii)
 			stmmac_mdio_reset(priv->mii);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index eb0b2898daa3d..fb160633ef347 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -10,6 +10,7 @@
 
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 #include <linux/module.h>
 #include <linux/io.h>
 #include <linux/of.h>
@@ -423,6 +424,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
 	if (plat->interface < 0)
 		plat->interface = plat->phy_interface;
 
+	/* Optional regulator for PHY */
+	plat->phy_regulator = devm_regulator_get_optional(&pdev->dev, "phy");
+	if (IS_ERR(plat->phy_regulator)) {
+		if (PTR_ERR(plat->phy_regulator) == -EPROBE_DEFER)
+			return ERR_CAST(plat->phy_regulator);
+		dev_info(&pdev->dev, "No regulator found\n");
+		plat->phy_regulator = NULL;
+	}
+
 	/* Some wrapper drivers still rely on phy_node. Let's save it while
 	 * they are not converted to phylink. */
 	plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 225751a8fd8e3..456bab4a3b362 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -209,6 +209,7 @@ struct plat_stmmacenet_data {
 	int phy_addr;
 	int interface;
 	phy_interface_t phy_interface;
+	struct regulator *phy_regulator;
 	struct stmmac_mdio_bus_data *mdio_bus_data;
 	struct device_node *phy_node;
 	struct device_node *phylink_node;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply
  2023-07-18 13:20 ` [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply Marco Felsch
@ 2023-07-20  4:12   ` Jakub Kicinski
  2023-07-20  6:46     ` Marco Felsch
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2023-07-20  4:12 UTC (permalink / raw)
  To: Marco Felsch
  Cc: davem, edumazet, pabeni, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, devicetree, netdev, linux-kernel, kernel,
	linux-stm32, linux-arm-kernel

On Tue, 18 Jul 2023 15:20:49 +0200 Marco Felsch wrote:
> Add generic phy-supply handling support to control the phy regulator to
> avoid handling it within the glue code. Use the generic stmmac_platform
> code to register a possible phy-supply and the stmmac_main code to
> handle the power on/off.
> 
> Changelog
> ---
> 
> v2:
> - adapt stmmac_phy_power
> - move power-on/off into stmmac_main to handle WOL
> - adapt commit message
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---

Format should be:

Bla bla bla

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Changelog

v2:
 bla bla bla


Please fix and rebase because the current version does not apply to
net-next/main.
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply
  2023-07-20  4:12   ` Jakub Kicinski
@ 2023-07-20  6:46     ` Marco Felsch
  2023-07-20 15:19       ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Felsch @ 2023-07-20  6:46 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, edumazet, pabeni, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, devicetree, netdev, linux-kernel, kernel,
	linux-stm32, linux-arm-kernel

Hi,

On 23-07-19, Jakub Kicinski wrote:
> On Tue, 18 Jul 2023 15:20:49 +0200 Marco Felsch wrote:
> > Add generic phy-supply handling support to control the phy regulator to
> > avoid handling it within the glue code. Use the generic stmmac_platform
> > code to register a possible phy-supply and the stmmac_main code to
> > handle the power on/off.
> > 
> > Changelog
> > ---
> > 
> > v2:
> > - adapt stmmac_phy_power
> > - move power-on/off into stmmac_main to handle WOL
> > - adapt commit message
> > 
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> 
> Format should be:
> 
> Bla bla bla
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> Changelog
> 
> v2:
>  bla bla bla
> 
> 
> Please fix and rebase because the current version does not apply to
> net-next/main.

Sure, I thought the changelog should be part of the commit message in
net-dev therefore I included it. Unfortunately I used --- as underline
:/

I will fix this and rebase it on-top of net-next/main.

Regards,
  Marco


> -- 
> pw-bot: cr
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply
  2023-07-20  6:46     ` Marco Felsch
@ 2023-07-20 15:19       ` Jakub Kicinski
  2023-07-20 15:38         ` Marco Felsch
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2023-07-20 15:19 UTC (permalink / raw)
  To: Marco Felsch
  Cc: davem, edumazet, pabeni, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, devicetree, netdev, linux-kernel, kernel,
	linux-stm32, linux-arm-kernel

On Thu, 20 Jul 2023 08:46:36 +0200 Marco Felsch wrote:
> > Please fix and rebase because the current version does not apply to
> > net-next/main.  
> 
> Sure, I thought the changelog should be part of the commit message in
> net-dev therefore I included it.

Old rules, I think. Since started adding lore links to all patches you
can put the changelog in the cut-off section. Adding a link to the
previous revision there is highly encouraged, too!
  
There's a sample of the preferred format at:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#changes-requested

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply
  2023-07-20 15:19       ` Jakub Kicinski
@ 2023-07-20 15:38         ` Marco Felsch
  0 siblings, 0 replies; 6+ messages in thread
From: Marco Felsch @ 2023-07-20 15:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, edumazet, pabeni, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, peppe.cavallaro, alexandre.torgue, joabreu,
	mcoquelin.stm32, devicetree, netdev, linux-kernel, kernel,
	linux-stm32, linux-arm-kernel

On 23-07-20, Jakub Kicinski wrote:
> On Thu, 20 Jul 2023 08:46:36 +0200 Marco Felsch wrote:
> > > Please fix and rebase because the current version does not apply to
> > > net-next/main.  
> > 
> > Sure, I thought the changelog should be part of the commit message in
> > net-dev therefore I included it.
> 
> Old rules, I think. Since started adding lore links to all patches you
> can put the changelog in the cut-off section.

Make sense.

> Adding a link to the previous revision there is highly encouraged,
> too!

Sure, I will check my tooling to use b4 for sending, so the links are
provided autom.

> There's a sample of the preferred format at:
> https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#changes-requested

I will keep that in mind.

Regards,
  Marco

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-20 15:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 13:20 [PATCH net-next v2 1/2] dt-bindings: net: snps,dwmac: add phy-supply support Marco Felsch
2023-07-18 13:20 ` [PATCH net-next v2 2/2] net: stmmac: add support for phy-supply Marco Felsch
2023-07-20  4:12   ` Jakub Kicinski
2023-07-20  6:46     ` Marco Felsch
2023-07-20 15:19       ` Jakub Kicinski
2023-07-20 15:38         ` Marco Felsch

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).