From: Marco Felsch <m.felsch@pengutronix.de> To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, mcoquelin.stm32@gmail.com Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH net-next 2/2] net: stmmac: platform: add support for phy-supply Date: Mon, 17 Jul 2023 18:43:07 +0200 [thread overview] Message-ID: <20230717164307.2868264-2-m.felsch@pengutronix.de> (raw) In-Reply-To: <20230717164307.2868264-1-m.felsch@pengutronix.de> Add generic phy-supply handling support to control the phy regulator. Use the common stmmac_platform code path so all drivers using stmmac_probe_config_dt() and stmmac_pltfr_pm_ops can use it. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> --- .../ethernet/stmicro/stmmac/stmmac_platform.c | 51 +++++++++++++++++++ include/linux/stmmac.h | 1 + 2 files changed, 52 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index eb0b2898daa3d..6193d42b53fb7 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); @@ -659,6 +669,38 @@ void stmmac_remove_config_dt(struct platform_device *pdev, EXPORT_SYMBOL_GPL(stmmac_probe_config_dt); EXPORT_SYMBOL_GPL(stmmac_remove_config_dt); +static int stmmac_phy_power(struct platform_device *pdev, + struct plat_stmmacenet_data *plat, + bool enable) +{ + struct regulator *regulator = plat->phy_regulator; + int ret = 0; + + if (regulator) { + if (enable) + ret = regulator_enable(regulator); + else + regulator_disable(regulator); + } + + if (ret) + dev_err(&pdev->dev, "Fail to enable regulator\n"); + + return ret; +} + +static int stmmac_phy_power_on(struct platform_device *pdev, + struct plat_stmmacenet_data *plat) +{ + return stmmac_phy_power(pdev, plat, true); +} + +static void stmmac_phy_power_off(struct platform_device *pdev, + struct plat_stmmacenet_data *plat) +{ + stmmac_phy_power(pdev, plat, false); +} + int stmmac_get_platform_resources(struct platform_device *pdev, struct stmmac_resources *stmmac_res) { @@ -720,6 +762,8 @@ int stmmac_pltfr_remove(struct platform_device *pdev) stmmac_remove_config_dt(pdev, plat); + stmmac_phy_power_off(pdev, plat); + return 0; } EXPORT_SYMBOL_GPL(stmmac_pltfr_remove); @@ -742,6 +786,8 @@ static int __maybe_unused stmmac_pltfr_suspend(struct device *dev) if (priv->plat->exit) priv->plat->exit(pdev, priv->plat->bsp_priv); + stmmac_phy_power_off(pdev, priv->plat); + return ret; } @@ -757,6 +803,11 @@ static int __maybe_unused stmmac_pltfr_resume(struct device *dev) struct net_device *ndev = dev_get_drvdata(dev); struct stmmac_priv *priv = netdev_priv(ndev); struct platform_device *pdev = to_platform_device(dev); + int ret; + + ret = stmmac_phy_power_on(pdev, priv->plat); + if (ret) + return ret; if (priv->plat->init) priv->plat->init(pdev, priv->plat->bsp_priv); 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
WARNING: multiple messages have this Message-ID (diff)
From: Marco Felsch <m.felsch@pengutronix.de> To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, mcoquelin.stm32@gmail.com Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH net-next 2/2] net: stmmac: platform: add support for phy-supply Date: Mon, 17 Jul 2023 18:43:07 +0200 [thread overview] Message-ID: <20230717164307.2868264-2-m.felsch@pengutronix.de> (raw) In-Reply-To: <20230717164307.2868264-1-m.felsch@pengutronix.de> Add generic phy-supply handling support to control the phy regulator. Use the common stmmac_platform code path so all drivers using stmmac_probe_config_dt() and stmmac_pltfr_pm_ops can use it. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> --- .../ethernet/stmicro/stmmac/stmmac_platform.c | 51 +++++++++++++++++++ include/linux/stmmac.h | 1 + 2 files changed, 52 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index eb0b2898daa3d..6193d42b53fb7 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); @@ -659,6 +669,38 @@ void stmmac_remove_config_dt(struct platform_device *pdev, EXPORT_SYMBOL_GPL(stmmac_probe_config_dt); EXPORT_SYMBOL_GPL(stmmac_remove_config_dt); +static int stmmac_phy_power(struct platform_device *pdev, + struct plat_stmmacenet_data *plat, + bool enable) +{ + struct regulator *regulator = plat->phy_regulator; + int ret = 0; + + if (regulator) { + if (enable) + ret = regulator_enable(regulator); + else + regulator_disable(regulator); + } + + if (ret) + dev_err(&pdev->dev, "Fail to enable regulator\n"); + + return ret; +} + +static int stmmac_phy_power_on(struct platform_device *pdev, + struct plat_stmmacenet_data *plat) +{ + return stmmac_phy_power(pdev, plat, true); +} + +static void stmmac_phy_power_off(struct platform_device *pdev, + struct plat_stmmacenet_data *plat) +{ + stmmac_phy_power(pdev, plat, false); +} + int stmmac_get_platform_resources(struct platform_device *pdev, struct stmmac_resources *stmmac_res) { @@ -720,6 +762,8 @@ int stmmac_pltfr_remove(struct platform_device *pdev) stmmac_remove_config_dt(pdev, plat); + stmmac_phy_power_off(pdev, plat); + return 0; } EXPORT_SYMBOL_GPL(stmmac_pltfr_remove); @@ -742,6 +786,8 @@ static int __maybe_unused stmmac_pltfr_suspend(struct device *dev) if (priv->plat->exit) priv->plat->exit(pdev, priv->plat->bsp_priv); + stmmac_phy_power_off(pdev, priv->plat); + return ret; } @@ -757,6 +803,11 @@ static int __maybe_unused stmmac_pltfr_resume(struct device *dev) struct net_device *ndev = dev_get_drvdata(dev); struct stmmac_priv *priv = netdev_priv(ndev); struct platform_device *pdev = to_platform_device(dev); + int ret; + + ret = stmmac_phy_power_on(pdev, priv->plat); + if (ret) + return ret; if (priv->plat->init) priv->plat->init(pdev, priv->plat->bsp_priv); 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-07-17 16:43 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-17 16:43 [PATCH net-next 1/2] dt-bindings: net: snps,dwmac: add phy-supply support Marco Felsch 2023-07-17 16:43 ` Marco Felsch 2023-07-17 16:43 ` Marco Felsch [this message] 2023-07-17 16:43 ` [PATCH net-next 2/2] net: stmmac: platform: add support for phy-supply Marco Felsch 2023-07-17 22:27 ` Andrew Lunn 2023-07-17 22:27 ` Andrew Lunn 2023-07-18 8:38 ` Marco Felsch 2023-07-18 8:38 ` Marco Felsch 2023-07-18 13:10 ` Andrew Lunn 2023-07-18 13:10 ` Andrew Lunn 2023-07-18 13:15 ` Marco Felsch 2023-07-18 13:15 ` Marco Felsch 2023-07-17 22:30 ` Andrew Lunn 2023-07-17 22:30 ` Andrew Lunn 2023-07-18 8:35 ` Marco Felsch 2023-07-18 8:35 ` Marco Felsch 2023-07-18 13:08 ` Andrew Lunn 2023-07-18 13:08 ` Andrew Lunn 2023-07-18 13:15 ` Marco Felsch 2023-07-18 13:15 ` Marco Felsch 2023-07-17 16:47 ` [PATCH net-next 1/2] dt-bindings: net: snps,dwmac: add phy-supply support Krzysztof Kozlowski 2023-07-17 16:47 ` Krzysztof Kozlowski 2023-07-17 16:57 ` Marco Felsch 2023-07-17 16:57 ` Marco Felsch 2023-07-18 7:59 ` Krzysztof Kozlowski 2023-07-18 7:59 ` Krzysztof Kozlowski 2023-07-18 8:00 ` Krzysztof Kozlowski 2023-07-18 8:00 ` Krzysztof Kozlowski
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=20230717164307.2868264-2-m.felsch@pengutronix.de \ --to=m.felsch@pengutronix.de \ --cc=alexandre.torgue@foss.st.com \ --cc=conor+dt@kernel.org \ --cc=davem@davemloft.net \ --cc=devicetree@vger.kernel.org \ --cc=edumazet@google.com \ --cc=joabreu@synopsys.com \ --cc=kernel@pengutronix.de \ --cc=krzysztof.kozlowski+dt@linaro.org \ --cc=kuba@kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-stm32@st-md-mailman.stormreply.com \ --cc=mcoquelin.stm32@gmail.com \ --cc=netdev@vger.kernel.org \ --cc=pabeni@redhat.com \ --cc=peppe.cavallaro@st.com \ --cc=robh+dt@kernel.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.