From: Corentin Labbe <clabbe@baylibre.com>
To: alexandre.torgue@foss.st.com, andrew@lunn.ch, broonie@kernel.org,
calvin.johnson@oss.nxp.com, davem@davemloft.net,
edumazet@google.com, hkallweit1@gmail.com,
jernej.skrabec@gmail.com, joabreu@synopsys.com,
krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org,
lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com,
peppe.cavallaro@st.com, robh+dt@kernel.org, samuel@sholland.org,
wens@csie.org
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev,
Corentin Labbe <clabbe@baylibre.com>
Subject: [PATCH 1/6] phy: handle optional regulator for PHY
Date: Mon, 9 May 2022 07:48:52 +0000 [thread overview]
Message-ID: <20220509074857.195302-2-clabbe@baylibre.com> (raw)
In-Reply-To: <20220509074857.195302-1-clabbe@baylibre.com>
Add handling of optional regulators for PHY.
Regulators need to be enabled before PHY scanning, so MDIO bus
initiate this task.
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
drivers/net/mdio/fwnode_mdio.c | 32 ++++++++++++++++++++++++++++++++
drivers/net/phy/phy_device.c | 20 ++++++++++++++++++++
include/linux/phy.h | 3 +++
3 files changed, 55 insertions(+)
diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index 1c1584fca632..c377cadc14c3 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -10,6 +10,7 @@
#include <linux/fwnode_mdio.h>
#include <linux/of.h>
#include <linux/phy.h>
+#include <linux/regulator/consumer.h>
MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
MODULE_LICENSE("GPL");
@@ -95,6 +96,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
bool is_c45 = false;
u32 phy_id;
int rc;
+ struct regulator *regulator_phy;
+ struct regulator *regulator_phy_io;
mii_ts = fwnode_find_mii_timestamper(child);
if (IS_ERR(mii_ts))
@@ -104,6 +107,32 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
"ethernet-phy-ieee802.3-c45");
if (rc >= 0)
is_c45 = true;
+ regulator_phy_io = devm_regulator_get_optional(&bus->dev, "phy-io");
+ if (IS_ERR(regulator_phy_io)) {
+ rc = PTR_ERR(regulator_phy_io);
+ if (rc == -ENODEV)
+ regulator_phy_io = NULL;
+ else
+ return rc;
+ }
+ regulator_phy = devm_regulator_get_optional(&bus->dev, "phy");
+ if (IS_ERR(regulator_phy)) {
+ rc = PTR_ERR(regulator_phy);
+ if (rc == -ENODEV)
+ regulator_phy = NULL;
+ else
+ return rc;
+ }
+ if (regulator_phy_io) {
+ rc = regulator_enable(regulator_phy_io);
+ if (rc)
+ return rc;
+ }
+ if (regulator_phy) {
+ rc = regulator_enable(regulator_phy);
+ if (rc)
+ return rc;
+ }
if (is_c45 || fwnode_get_phy_id(child, &phy_id))
phy = get_phy_device(bus, addr, is_c45);
@@ -114,6 +143,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
return PTR_ERR(phy);
}
+ phy->regulator_phy = regulator_phy;
+ phy->regulator_phy_io = regulator_phy_io;
+
if (is_acpi_node(child)) {
phy->irq = bus->irq[addr];
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 431a8719c635..ce64df596580 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -27,6 +27,7 @@
#include <linux/phy.h>
#include <linux/phy_led_triggers.h>
#include <linux/property.h>
+#include <linux/regulator/consumer.h>
#include <linux/sfp.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
@@ -1785,6 +1786,11 @@ int phy_suspend(struct phy_device *phydev)
if (!ret)
phydev->suspended = true;
+ if (phydev->regulator_phy)
+ regulator_disable(phydev->regulator_phy);
+ if (phydev->regulator_phy_io)
+ regulator_disable(phydev->regulator_phy_io);
+
return ret;
}
EXPORT_SYMBOL(phy_suspend);
@@ -1811,6 +1817,20 @@ int phy_resume(struct phy_device *phydev)
{
int ret;
+ if (phydev->regulator_phy_io) {
+ ret = regulator_enable(phydev->regulator_phy_io);
+ if (ret)
+ return ret;
+ }
+ if (phydev->regulator_phy) {
+ ret = regulator_enable(phydev->regulator_phy);
+ if (ret) {
+ if (phydev->regulator_phy_io)
+ regulator_disable(phydev->regulator_phy_io);
+ return ret;
+ }
+ }
+
mutex_lock(&phydev->lock);
ret = __phy_resume(phydev);
mutex_unlock(&phydev->lock);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 2d12054932ba..c29f45668d94 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -704,6 +704,9 @@ struct phy_device {
void (*phy_link_change)(struct phy_device *phydev, bool up);
void (*adjust_link)(struct net_device *dev);
+ struct regulator *regulator_phy;
+ struct regulator *regulator_phy_io;
+
#if IS_ENABLED(CONFIG_MACSEC)
/* MACsec management functions */
const struct macsec_ops *macsec_ops;
--
2.35.1
next prev parent reply other threads:[~2022-05-09 7:52 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-09 7:48 [PATCH 0/6] arm64: add ethernet to orange pi 3 Corentin Labbe
2022-05-09 7:48 ` Corentin Labbe [this message]
2022-05-09 7:48 ` [PATCH 2/6] net: stmmac: dwmac-sun8i: remove regulator Corentin Labbe
2022-05-09 14:09 ` Andre Przywara
2022-05-09 14:38 ` LABBE Corentin
2022-05-09 7:48 ` [PATCH 3/6] dt-bindings: net: Add documentation for phy-supply Corentin Labbe
2022-05-09 12:17 ` Andrew Lunn
2022-05-09 13:26 ` LABBE Corentin
2022-05-09 16:02 ` Andrew Lunn
2022-05-09 16:12 ` Mark Brown
2022-05-09 16:38 ` Andrew Lunn
2022-05-09 16:56 ` Mark Brown
2022-05-11 8:02 ` LABBE Corentin
2022-05-11 12:50 ` Mark Brown
2022-05-17 0:47 ` Rob Herring
2022-05-09 7:48 ` [PATCH 4/6] ARM: dts: sunxi: move phy regulator in PHY node Corentin Labbe
2022-05-09 10:55 ` Andre Przywara
2022-05-09 11:16 ` LABBE Corentin
2022-05-09 7:48 ` [PATCH 5/6] arm64: dts: allwinner: " Corentin Labbe
2022-05-09 7:48 ` [PATCH 6/6] arm64: dts: allwinner: orange-pi-3: Enable ethernet Corentin Labbe
2022-05-09 12:20 ` [PATCH 0/6] arm64: add ethernet to orange pi 3 Andrew Lunn
2022-05-09 13:27 ` LABBE Corentin
2022-05-09 15:19 ` Andrew Lunn
2022-05-09 15:24 ` LABBE Corentin
2022-05-09 15:56 ` Mark Brown
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=20220509074857.195302-2-clabbe@baylibre.com \
--to=clabbe@baylibre.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew@lunn.ch \
--cc=broonie@kernel.org \
--cc=calvin.johnson@oss.nxp.com \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=joabreu@synopsys.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
--cc=robh+dt@kernel.org \
--cc=samuel@sholland.org \
--cc=wens@csie.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: 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;
as well as URLs for NNTP newsgroup(s).