From: Heiko Stuebner <heiko@sntech.de>
To: andrew@lunn.ch, hkallweit1@gmail.com
Cc: linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
quentin.schulz@theobroma-systems.com, heiko@sntech.de,
Heiko Stuebner <heiko.stuebner@cherry.de>
Subject: [PATCH] net: mdio: enable optional clock when registering a phy from devicetree
Date: Fri, 1 Dec 2023 15:24:53 +0100 [thread overview]
Message-ID: <20231201142453.324697-1-heiko@sntech.de> (raw)
From: Heiko Stuebner <heiko.stuebner@cherry.de>
The ethernet-phy binding (now) specifys that phys can declare a clock
supply. Phy driver itself will handle this when probing the phy-driver.
But there is a gap when trying to detect phys, because the mdio-bus needs
to talk to the phy to get its phy-id. Using actual phy-ids in the dt like
compatible = "ethernet-phy-id0022.1640",
"ethernet-phy-ieee802.3-c22";
of course circumvents this, but in turn hard-codes the phy.
With boards often having multiple phy options and the mdio-bus being able
to actually probe devices, this feels like a step back.
So check for the existence of a phy-clock per the -dtbinding in the
of_mdiobus_register_phy() and enable the clock around the
fwnode_mdiobus_register_phy() call which tries to determine the phy-id.
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
drivers/net/mdio/of_mdio.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c
index 64ebcb6d235c..895b12849b23 100644
--- a/drivers/net/mdio/of_mdio.c
+++ b/drivers/net/mdio/of_mdio.c
@@ -8,6 +8,7 @@
* out of the OpenFirmware device tree and using it to populate an mii_bus.
*/
+#include <linux/clk.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/fwnode_mdio.h>
@@ -15,6 +16,7 @@
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/of.h>
+#include <linux/of_clk.h>
#include <linux/of_irq.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
@@ -46,7 +48,37 @@ EXPORT_SYMBOL(of_mdiobus_phy_device_register);
static int of_mdiobus_register_phy(struct mii_bus *mdio,
struct device_node *child, u32 addr)
{
- return fwnode_mdiobus_register_phy(mdio, of_fwnode_handle(child), addr);
+ struct clk *clk = NULL;
+ int ret;
+
+ /* ethernet-phy binding specifies a maximum of 1 clock */
+ if (of_clk_get_parent_count(child) == 1) {
+ clk = of_clk_get(child, 0);
+ if (IS_ERR(clk)) {
+ if (PTR_ERR(clk) != -ENOENT)
+ return dev_err_probe(&mdio->dev, PTR_ERR(clk),
+ "Could not get defined clock for MDIO device at address %u\n",
+ addr);
+
+ clk = NULL;
+ }
+ }
+
+ ret = clk_prepare_enable(clk);
+ if (ret < 0) {
+ clk_put(clk);
+ dev_err(&mdio->dev,
+ "Could not enable clock for MDIO device at address %u: %d\n",
+ addr, ret);
+ return ret;
+ }
+
+ ret = fwnode_mdiobus_register_phy(mdio, of_fwnode_handle(child), addr);
+
+ clk_disable_unprepare(clk);
+ clk_put(clk);
+
+ return ret;
}
static int of_mdiobus_register_device(struct mii_bus *mdio,
--
2.39.2
next reply other threads:[~2023-12-01 14:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-01 14:24 Heiko Stuebner [this message]
2023-12-01 22:15 ` Andrew Lunn
2023-12-04 9:43 ` Quentin Schulz
2023-12-06 16:04 ` Andrew Lunn
2023-12-01 22:41 ` Florian Fainelli
2023-12-04 10:14 ` Quentin Schulz
2023-12-04 10:22 ` Heiko Stübner
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=20231201142453.324697-1-heiko@sntech.de \
--to=heiko@sntech.de \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=heiko.stuebner@cherry.de \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quentin.schulz@theobroma-systems.com \
/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
all inboxes | Powered by JetHome®