mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 03/10] net: phy: register phys specified in devicetree
Date: Wed, 21 May 2014 14:18:53 +0200	[thread overview]
Message-ID: <1400674740-6467-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1400674740-6467-1-git-send-email-s.hauer@pengutronix.de>

When a mdio bus has a device node attached then register the phys
specified there. This makes it possible to lookup the phys using
phandles later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 5c4dea4..ca01673 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -49,6 +49,71 @@ int mdiobus_detect(struct device_d *dev)
 	return 0;
 }
 
+static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child,
+				   u32 addr)
+{
+	struct phy_device *phy;
+	int ret;
+
+	phy = get_phy_device(mdio, addr);
+	if (IS_ERR(phy))
+		return PTR_ERR(phy);
+
+	/*
+	 * Associate the OF node with the device structure so it
+	 * can be looked up later
+	 */
+	phy->dev.device_node = child;
+
+	/*
+	 * All data is now stored in the phy struct;
+	 * register it
+	 */
+	ret = phy_register_device(phy);
+	if (ret)
+		return ret;
+
+	dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
+		child->name, addr);
+
+	return 0;
+}
+
+/**
+ * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
+ * @mdio: pointer to mii_bus structure
+ * @np: pointer to device_node of MDIO bus.
+ *
+ * This function registers the mii_bus structure and registers a phy_device
+ * for each child node of @np.
+ */
+static int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
+{
+	struct device_node *child;
+	u32 addr;
+	int ret;
+
+	/* Loop over the child nodes and register a phy_device for each one */
+	for_each_available_child_of_node(np, child) {
+		ret = of_property_read_u32(child, "reg", &addr);
+		if (ret) {
+			dev_err(&mdio->dev, "%s has invalid PHY address\n",
+				child->full_name);
+			continue;
+		}
+
+		if (addr >= PHY_MAX_ADDR) {
+			dev_err(&mdio->dev, "%s PHY address %i is too large\n",
+				child->full_name, addr);
+			continue;
+		}
+
+		of_mdiobus_register_phy(mdio, child, addr);
+	}
+
+	return 0;
+}
+
 /**
  * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
  * @bus: target mii_bus
@@ -85,6 +150,10 @@ int mdiobus_register(struct mii_bus *bus)
 	list_add_tail(&bus->list, &mii_bus_list);
 
 	pr_info("%s: probed\n", dev_name(&bus->dev));
+
+	if (bus->dev.device_node)
+		of_mdiobus_register(bus, bus->dev.device_node);
+
 	return 0;
 }
 EXPORT_SYMBOL(mdiobus_register);
-- 
2.0.0.rc0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-05-21 12:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-21 12:18 [PATCH] devicetree support for ethernet phys Sascha Hauer
2014-05-21 12:18 ` [PATCH 01/10] net: phy: factor out phy_device_attach function Sascha Hauer
2014-05-21 12:18 ` [PATCH 02/10] net: phy: move setting of phy_map to phy_register_device Sascha Hauer
2014-05-21 12:18 ` Sascha Hauer [this message]
2014-05-21 12:18 ` [PATCH 04/10] net: phy: Support finding a phy in the devicetree Sascha Hauer
2014-05-21 12:18 ` [PATCH 05/10] net: phy: Support limiting phy speed " Sascha Hauer
2014-05-21 12:28   ` Sebastian Hesselbarth
2014-05-21 12:18 ` [PATCH 06/10] net: orion-gbe: use transparent-to-driver of mdio functions Sascha Hauer
2014-05-21 12:29   ` Sebastian Hesselbarth
2014-05-22 20:09   ` Sebastian Hesselbarth
2014-08-02 17:44   ` Ezequiel Garcia
2014-08-04 18:42     ` Sascha Hauer
2014-05-21 12:18 ` [PATCH 07/10] net: phy: remove now unused of_phy_device_connect Sascha Hauer
2014-05-21 12:18 ` [PATCH 08/10] net: phy: genphy: always write MII_CTRL1000 when available Sascha Hauer
2014-05-21 12:18 ` [PATCH 09/10] net: phy: genphy: Make it work with of_set_phy_supported Sascha Hauer
2014-05-21 12:19 ` [PATCH 10/10] net: fec_imx: Add devicetree support for mdio bus Sascha Hauer

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=1400674740-6467-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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