[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220331092533.348626-5-clement.leger@bootlin.com>
Date: Thu, 31 Mar 2022 11:25:26 +0200
From: Clément Léger <clement.leger@...tlin.com>
To: Andrew Lunn <andrew@...n.ch>,
Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
"David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>
Cc: Horatiu Vultur <horatiu.vultur@...rochip.com>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Allan Nielsen <allan.nielsen@...rochip.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
Clément Léger <clement.leger@...tlin.com>
Subject: [RFC PATCH net-next v2 04/11] net: mdio: fwnode: convert fwnode_mdiobus_register() for fwnode
First version was added as a simple copy of of_mdiobus_register() to
allow compiling and being able to see the diff of modifications that
are going to be done. This commits convert the code that was imported
to handle a fwnode_handle properly.
Signed-off-by: Clément Léger <clement.leger@...tlin.com>
---
drivers/net/mdio/fwnode_mdio.c | 76 ++++++++++++++++++++++------------
1 file changed, 50 insertions(+), 26 deletions(-)
diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index 38c873c49ecf..319cccd0edeb 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -146,10 +146,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
}
EXPORT_SYMBOL(fwnode_mdiobus_register_phy);
-static int of_mdiobus_register_device(struct mii_bus *mdio,
- struct device_node *child, u32 addr)
+static int fwnode_mdiobus_register_device(struct mii_bus *mdio,
+ struct fwnode_handle *child, u32 addr)
{
- struct fwnode_handle *fwnode = of_fwnode_handle(child);
struct mdio_device *mdiodev;
int rc;
@@ -160,18 +159,18 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,
/* Associate the OF node with the device structure so it
* can be looked up later.
*/
- fwnode_handle_get(fwnode);
- device_set_node(&mdiodev->dev, fwnode);
+ fwnode_handle_get(child);
+ device_set_node(&mdiodev->dev, child);
/* All data is now stored in the mdiodev struct; register it. */
rc = mdio_device_register(mdiodev);
if (rc) {
mdio_device_free(mdiodev);
- of_node_put(child);
+ fwnode_handle_put(child);
return rc;
}
- dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n",
+ dev_dbg(&mdio->dev, "registered mdio device %pfwP at address %i\n",
child, addr);
return 0;
}
@@ -186,26 +185,51 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,
* A device which is not a phy is expected to have a compatible string
* indicating what sort of device it is.
*/
-bool fwnode_mdiobus_child_is_phy(struct device_node *child)
+bool fwnode_mdiobus_child_is_phy(struct fwnode_handle *child)
{
u32 phy_id;
- if (of_get_phy_id(child, &phy_id) != -EINVAL)
+ if (fwnode_get_phy_id(child, &phy_id) != -EINVAL)
return true;
- if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"))
+ if (fwnode_property_match_string(child, "compatible",
+ "ethernet-phy-ieee802.3-c45") >= 0)
return true;
- if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22"))
+ if (fwnode_property_match_string(child, "compatible",
+ "ethernet-phy-ieee802.3-c22") >= 0)
return true;
- if (!of_find_property(child, "compatible", NULL))
+ if (!fwnode_property_present(child, "compatible"))
return true;
return false;
}
EXPORT_SYMBOL(fwnode_mdiobus_child_is_phy);
+int fwnode_mdio_parse_addr(struct device *dev,
+ const struct fwnode_handle *fwnode)
+{
+ u32 addr;
+ int ret;
+
+ ret = fwnode_property_read_u32(fwnode, "reg", &addr);
+ if (ret < 0) {
+ dev_err(dev, "%pfwP has invalid PHY address\n", fwnode);
+ return ret;
+ }
+
+ /* A PHY must have a reg property in the range [0-31] */
+ if (addr >= PHY_MAX_ADDR) {
+ dev_err(dev, "%pfwP PHY address %i is too large\n",
+ fwnode, addr);
+ return -EINVAL;
+ }
+
+ return addr;
+}
+EXPORT_SYMBOL(fwnode_mdio_parse_addr);
+
/**
* of_mdiobus_register - Register mii_bus and create PHYs from the device tree
* @mdio: pointer to mii_bus structure
@@ -214,29 +238,31 @@ EXPORT_SYMBOL(fwnode_mdiobus_child_is_phy);
* This function registers the mii_bus structure and registers a phy_device
* for each child node of @np.
*/
-int fwnode_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
+int fwnode_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode)
{
- struct device_node *child;
+ struct fwnode_handle *child;
int addr, rc;
- if (!np)
+ if (!fwnode)
return mdiobus_register(mdio);
/* Do not continue if the node is disabled */
- if (!of_device_is_available(np))
+ if (!fwnode_device_is_available(fwnode))
return -ENODEV;
/* Mask out all PHYs from auto probing. Instead the PHYs listed in
* the device tree are populated after the bus has been registered */
mdio->phy_mask = ~0;
- device_set_node(&mdio->dev, of_fwnode_handle(np));
+ device_set_node(&mdio->dev, fwnode);
/* Get bus level PHY reset GPIO details */
mdio->reset_delay_us = DEFAULT_GPIO_RESET_DELAY;
- of_property_read_u32(np, "reset-delay-us", &mdio->reset_delay_us);
+ fwnode_property_read_u32(fwnode, "reset-delay-us",
+ &mdio->reset_delay_us);
mdio->reset_post_delay_us = 0;
- of_property_read_u32(np, "reset-post-delay-us", &mdio->reset_post_delay_us);
+ fwnode_property_read_u32(fwnode, "reset-post-delay-us",
+ &mdio->reset_post_delay_us);
/* Register the MDIO bus */
rc = mdiobus_register(mdio);
@@ -244,17 +270,15 @@ int fwnode_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
return rc;
/* Loop over the child nodes and register a phy_device for each phy */
- for_each_available_child_of_node(np, child) {
- addr = of_mdio_parse_addr(&mdio->dev, child);
+ fwnode_for_each_available_child_node(fwnode, child) {
+ addr = fwnode_mdio_parse_addr(&mdio->dev, child);
if (addr < 0)
continue;
- if (of_mdiobus_child_is_phy(child))
- rc = fwnode_mdiobus_register_phy(mdio,
- of_fwnode_handle(child),
- addr);
+ if (fwnode_mdiobus_child_is_phy(child))
+ rc = fwnode_mdiobus_register_phy(mdio, child, addr);
else
- rc = of_mdiobus_register_device(mdio, child, addr);
+ rc = fwnode_mdiobus_register_device(mdio, child, addr);
if (rc == -ENODEV)
dev_err(&mdio->dev,
--
2.34.1
Powered by blists - more mailing lists