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 04/10] net: phy: Support finding a phy in the devicetree
Date: Wed, 21 May 2014 14:18:54 +0200	[thread overview]
Message-ID: <1400674740-6467-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1400674740-6467-1-git-send-email-s.hauer@pengutronix.de>

When the ethernet device has a device_node then try finding
the associated phy via the phy-handle property.

This makes the phy handling via devicetree transparent to the
ethernet drivers.

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

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 1e26e45..257df74 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -262,6 +262,29 @@ int phy_register_device(struct phy_device* dev)
 	return ret;
 }
 
+static struct phy_device *of_mdio_find_phy(struct eth_device *edev)
+{
+	struct device_d *dev;
+	struct device_node *phy_node;
+
+	if (!IS_ENABLED(CONFIG_OFDEVICE))
+		return NULL;
+
+	if (!edev->parent->device_node)
+		return NULL;
+
+	phy_node = of_parse_phandle(edev->parent->device_node, "phy-handle", 0);
+	if (!phy_node)
+		return NULL;
+
+	bus_for_each_device(&mdio_bus_type, dev) {
+		if (dev->device_node == phy_node)
+			return container_of(dev, struct phy_device, dev);
+	}
+
+	return NULL;
+}
+
 static int phy_device_attach(struct phy_device *phy, struct eth_device *edev,
 		       void (*adjust_link) (struct eth_device *edev),
 		       u32 flags, phy_interface_t interface)
@@ -312,6 +335,13 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 		return 0;
 	}
 
+	phy = of_mdio_find_phy(edev);
+	if (phy) {
+		ret = phy_device_attach(phy, edev, adjust_link, flags, interface);
+
+		goto out;
+	}
+
 	if (addr >= 0) {
 		phy = mdiobus_scan(bus, addr);
 		if (IS_ERR(phy)) {
-- 
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 ` [PATCH 03/10] net: phy: register phys specified in devicetree Sascha Hauer
2014-05-21 12:18 ` Sascha Hauer [this message]
2014-05-21 12:18 ` [PATCH 05/10] net: phy: Support limiting phy speed in the devicetree 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-5-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