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 2/9] net: phy: bail out early in phy_device_connect
Date: Wed, 11 Dec 2013 12:41:10 +0100	[thread overview]
Message-ID: <1386762077-23205-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1386762077-23205-1-git-send-email-s.hauer@pengutronix.de>

If an ethernet device already has a phy in phy_device_connect all we
have to do is to start autonegotiation. Do this early and bail out
so that for the rest of the code it's clear that we have to search for
a phy device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/phy.c | 66 +++++++++++++++++++++++++++++----------------------
 include/linux/phy.h   |  1 -
 2 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d8966cd..a83b35c 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -224,6 +224,14 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr)
 	return dev;
 }
 
+static void phy_config_aneg(struct phy_device *phydev)
+{
+	struct phy_driver *drv;
+
+	drv = to_phy_driver(phydev->dev.driver);
+	drv->config_aneg(phydev);
+}
+
 static int phy_register_device(struct phy_device* dev)
 {
 	int ret;
@@ -246,18 +254,37 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 		       void (*adjust_link) (struct eth_device *edev),
 		       u32 flags, phy_interface_t interface)
 {
-	struct phy_driver* drv;
 	struct phy_device* dev = NULL;
 	unsigned int i;
 	int ret = -EINVAL;
 
-	if (!edev->phydev) {
-		if (addr >= 0) {
-			dev = mdiobus_scan(bus, addr);
-			if (IS_ERR(dev)) {
-				ret = -EIO;
-				goto fail;
-			}
+	if (edev->phydev) {
+		phy_config_aneg(edev->phydev);
+		return 0;
+	}
+
+	if (addr >= 0) {
+		dev = mdiobus_scan(bus, addr);
+		if (IS_ERR(dev)) {
+			ret = -EIO;
+			goto fail;
+		}
+
+		dev->interface = interface;
+		dev->dev_flags = flags;
+
+		ret = phy_register_device(dev);
+		if (ret)
+			goto fail;
+	} else {
+		for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
+			/* skip masked out PHY addresses */
+			if (bus->phy_mask & (1 << i))
+				continue;
+
+			dev = mdiobus_scan(bus, i);
+			if (IS_ERR(dev) || dev->attached_dev)
+				continue;
 
 			dev->interface = interface;
 			dev->dev_flags = flags;
@@ -265,33 +292,14 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 			ret = phy_register_device(dev);
 			if (ret)
 				goto fail;
-		} else {
-			for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
-				/* skip masked out PHY addresses */
-				if (bus->phy_mask & (1 << i))
-					continue;
 
-				dev = mdiobus_scan(bus, i);
-				if (IS_ERR(dev) || dev->attached_dev)
-					continue;
-
-				dev->interface = interface;
-				dev->dev_flags = flags;
-
-				ret = phy_register_device(dev);
-				if (ret)
-					goto fail;
-
-				break;
-			}
+			break;
 		}
 	}
 
 	edev->phydev = dev;
 	dev->attached_dev = edev;
-	drv = to_phy_driver(dev->dev.driver);
-
-	drv->config_aneg(dev);
+	phy_config_aneg(edev->phydev);
 
 	dev->adjust_link = adjust_link;
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 94f631b..a1c629e 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -161,7 +161,6 @@ struct phy_device {
 	int autoneg;
 	int force;
 
-
 	/* private data pointer */
 	/* For use by PHYs to maintain extra state */
 	void *priv;
-- 
1.8.5.1


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

  parent reply	other threads:[~2013-12-11 11:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11 11:41 mii patches Sascha Hauer
2013-12-11 11:41 ` [PATCH 1/9] net: phy: cleanup attached device handling Sascha Hauer
2013-12-11 11:41 ` Sascha Hauer [this message]
2013-12-11 11:41 ` [PATCH 3/9] net: phy: move duplicated code out of if/else Sascha Hauer
2013-12-11 11:41 ` [PATCH 4/9] net: phy: check if a phy already has an ethernet device Sascha Hauer
2013-12-11 11:41 ` [PATCH 5/9] net: phy: track registered state of a phy device Sascha Hauer
2013-12-11 11:41 ` [PATCH 6/9] net: phy: move phy_init_hw to phy_device_connect Sascha Hauer
2013-12-11 11:41 ` [PATCH 7/9] net: phy: Track mii buses on a list Sascha Hauer
2013-12-11 11:41 ` [PATCH 8/9] net: phy: implement detect callback for miibus devices Sascha Hauer
2013-12-11 11:41 ` [PATCH 9/9] miitool: Add option to scan mii buses 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=1386762077-23205-3-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