mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	barebox@lists.infradead.org,
	Michael Grzeschik <mgr@pengutronix.de>
Subject: [PATCH 2/6] net: phy: add of_phy_device_connect
Date: Wed,  5 Feb 2014 23:40:05 +0100	[thread overview]
Message-ID: <1391640009-3399-3-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1391640009-3399-1-git-send-email-sebastian.hesselbarth@gmail.com>

This implements a of_phy_device_connect to allow DT enabled drivers
to connect to a PHY device by using the PHY's DT node only. It
currently assumes that each PHY node is a child of the corresponding
mdio bus.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
I haven't looked closely at the Linux fixed-phy discussion, so the
actual implementation might have to change for PHYs without mdio parent
bus. Anyway, for now it is sufficient to only support mdio bus attached
PHYs.

Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Michael Grzeschik <mgr@pengutronix.de>
Cc: barebox@lists.infradead.org
---
 drivers/net/phy/phy.c | 31 +++++++++++++++++++++++++++++++
 include/linux/phy.h   | 14 ++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index faa5c26c227d..879939d4a2f0 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -331,6 +331,37 @@ fail:
 	return ret;
 }
 
+#if defined(CONFIG_OFTREE)
+int of_phy_device_connect(struct eth_device *edev, struct device_node *phy_np,
+			  void (*adjust_link) (struct eth_device *edev),
+			  u32 flags, phy_interface_t interface)
+{
+	struct device_node *bus_np;
+	struct mii_bus *miibus;
+	int phy_addr = -ENODEV;
+
+	if (!phy_np)
+		return -EINVAL;
+
+	of_property_read_u32(phy_np, "reg", &phy_addr);
+
+	bus_np = of_get_parent(phy_np);
+	if (!bus_np)
+		return -ENODEV;
+
+	for_each_mii_bus(miibus) {
+		if (miibus->parent && miibus->parent->device_node == bus_np)
+			return phy_device_connect(edev, miibus, phy_addr,
+					  adjust_link, flags, interface);
+	}
+
+	dev_err(&edev->dev, "unable to mdio bus for phy %s\n",
+		phy_np->full_name);
+
+	return -ENODEV;
+}
+#endif
+
 /* Generic PHY support and helper functions */
 
 /**
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 9994e1107de5..76375f06f41f 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -280,6 +280,20 @@ int phy_device_connect(struct eth_device *dev, struct mii_bus *bus, int addr,
 		       void (*adjust_link) (struct eth_device *edev),
 		       u32 flags, phy_interface_t interface);
 
+#if defined(CONFIG_OFTREE)
+int of_phy_device_connect(struct eth_device *edev, struct device_node *phy_np,
+			  void (*adjust_link) (struct eth_device *edev),
+			  u32 flags, phy_interface_t interface);
+#else
+static inline int of_phy_device_connect(struct eth_device *edev,
+				struct device_node *phy_np,
+				void (*adjust_link) (struct eth_device *edev),
+				u32 flags, phy_interface_t interface)
+{
+	return -ENOSYS;
+}
+#endif
+
 int phy_update_status(struct phy_device *phydev);
 int phy_wait_aneg_done(struct phy_device *phydev);
 
-- 
1.8.5.3


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

  parent reply	other threads:[~2014-02-05 22:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05 22:40 [PATCH 0/6] Marvell MVEBU mbus and Orion GBE driver Sebastian Hesselbarth
2014-02-05 22:40 ` [PATCH 1/6] net: reorder Kconfig and Makefile alphabetically Sebastian Hesselbarth
2014-02-05 22:40 ` Sebastian Hesselbarth [this message]
2014-02-05 22:40 ` [PATCH 3/6] bus: mvebu: add mbus driver Sebastian Hesselbarth
2014-02-07  6:58   ` Sascha Hauer
2014-02-07  9:19     ` Sebastian Hesselbarth
2014-02-07 13:06     ` Sebastian Hesselbarth
2014-02-07 17:41   ` [PATCH v2 3/7] " Sebastian Hesselbarth
2014-02-05 22:40 ` [PATCH 4/6] net: phy: add mvebu mdio bus driver Sebastian Hesselbarth
2014-02-05 22:40 ` [PATCH 5/6] net: orion: add ethernet driver Sebastian Hesselbarth
2014-02-05 22:40 ` [PATCH 6/6] ARM: dove: sync with DT files from Linux Sebastian Hesselbarth
2014-02-07  9:33   ` Sebastian Hesselbarth
2014-02-07 11:03     ` Sascha Hauer
2014-02-07 17:42   ` [PATCH v2 6/7] ARM: dove: separate barebox-specific DT changes Sebastian Hesselbarth
2014-02-07 17:42     ` [PATCH v2 6/7] ARM: dove: sync with DT files from Linux Sebastian Hesselbarth
2014-02-07 17:45       ` Sebastian Hesselbarth
2014-02-10  8:11         ` Sascha Hauer
2014-02-07  7:21 ` [PATCH 0/6] Marvell MVEBU mbus and Orion GBE driver Sascha Hauer
2014-02-07  9:22   ` Sebastian Hesselbarth
2014-02-07  9:51     ` 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=1391640009-3399-3-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=mgr@pengutronix.de \
    --cc=thomas.petazzoni@free-electrons.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