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 1/4] net: phy: introduce phy_aneg_done
Date: Thu, 18 Sep 2014 09:11:12 +0200	[thread overview]
Message-ID: <1411024275-31766-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1411024275-31766-1-git-send-email-s.hauer@pengutronix.de>

phy_wait_aneg_done() is directly called by the network code, so it
should not read phy registers directly. Introduce phy_aneg_done to
give phy drivers the chance to do something different to poll for
autonegotiation completion.

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

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index cad4cf5..7604e1d 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -31,6 +31,21 @@
 static struct phy_driver genphy_driver;
 static int genphy_config_init(struct phy_device *phydev);
 
+/**
+ * phy_aneg_done - return auto-negotiation status
+ * @phydev: target phy_device struct
+ *
+ * Description: Return the auto-negotiation status from this @phydev
+ * Returns > 0 on success or < 0 on error. 0 means that auto-negotiation
+ * is still pending.
+ */
+static int phy_aneg_done(struct phy_device *phydev)
+{
+	struct phy_driver *drv = to_phy_driver(phydev->dev.driver);
+
+	return drv->aneg_done(phydev);
+}
+
 int phy_update_status(struct phy_device *dev)
 {
 	struct phy_driver *drv = to_phy_driver(dev->dev.driver);
@@ -477,25 +492,15 @@ int genphy_setup_forced(struct phy_device *phydev)
 int phy_wait_aneg_done(struct phy_device *phydev)
 {
 	uint64_t start = get_time_ns();
-	int ctl;
 
 	if (phydev->autoneg == AUTONEG_DISABLE)
 		return 0;
 
 	while (!is_timeout(start, PHY_AN_TIMEOUT * SECOND)) {
-		ctl = phy_read(phydev, MII_BMSR);
-		if (ctl & BMSR_ANEGCOMPLETE) {
+		if (phy_aneg_done(phydev) > 0) {
 			phydev->link = 1;
 			return 0;
 		}
-
-		/* Restart auto-negotiation if remote fault */
-		if (ctl & BMSR_RFAULT) {
-			puts("PHY remote fault detected\n"
-			     "PHY restarting auto-negotiation\n");
-			phy_write(phydev, MII_BMCR,
-					  BMCR_ANENABLE | BMCR_ANRESTART);
-		}
 	}
 
 	phydev->link = 0;
@@ -572,6 +577,33 @@ int genphy_config_aneg(struct phy_device *phydev)
 }
 
 /**
+ * genphy_aneg_done - return auto-negotiation status
+ * @phydev: target phy_device struct
+ *
+ * Description: Reads the status register and returns 0 either if
+ *   auto-negotiation is incomplete, or if there was an error.
+ *   Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
+ */
+int genphy_aneg_done(struct phy_device *phydev)
+{
+	int bmsr = phy_read(phydev, MII_BMSR);
+
+	if (bmsr < 0)
+		return bmsr;
+
+	/* Restart auto-negotiation if remote fault */
+	if (bmsr & BMSR_RFAULT) {
+		puts("PHY remote fault detected\n"
+		     "PHY restarting auto-negotiation\n");
+		phy_write(phydev, MII_BMCR,
+				  BMCR_ANENABLE | BMCR_ANRESTART);
+	}
+
+	return bmsr & BMSR_ANEGCOMPLETE;
+}
+EXPORT_SYMBOL(genphy_aneg_done);
+
+/**
  * genphy_update_link - update link status in @phydev
  * @phydev: target phy_device struct
  *
@@ -825,6 +857,9 @@ int phy_driver_register(struct phy_driver *phydrv)
 	if (!phydrv->config_aneg)
 		phydrv->config_aneg = genphy_config_aneg;
 
+	if (!phydrv->aneg_done)
+		phydrv->aneg_done = genphy_aneg_done;
+
 	if (!phydrv->read_status)
 		phydrv->read_status = genphy_read_status;
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 7c5d754..c0fd4ff 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -234,6 +234,9 @@ struct phy_driver {
 	 */
 	int (*config_aneg)(struct phy_device *phydev);
 
+	/* Determines the auto negotiation result */
+	int (*aneg_done)(struct phy_device *phydev);
+
 	/* Determines the negotiated speed and duplex */
 	int (*read_status)(struct phy_device *phydev);
 
@@ -295,6 +298,7 @@ int phy_wait_aneg_done(struct phy_device *phydev);
 /* Generic PHY support and helper functions */
 int genphy_restart_aneg(struct phy_device *phydev);
 int genphy_config_aneg(struct phy_device *phydev);
+int genphy_aneg_done(struct phy_device *phydev);
 int genphy_update_link(struct phy_device *phydev);
 int genphy_read_status(struct phy_device *phydev);
 int genphy_config_advert(struct phy_device *phydev);
-- 
2.1.0


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

  reply	other threads:[~2014-09-18  7:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18  7:11 net: phy updates Sascha Hauer
2014-09-18  7:11 ` Sascha Hauer [this message]
2014-09-18  7:11 ` [PATCH 2/4] net: phy: Use xzalloc for small allocations Sascha Hauer
2014-09-18  7:11 ` [PATCH 3/4] net: phy: don't use 'dev' as name for variables of type struct phy_device Sascha Hauer
2014-09-18  7:11 ` [PATCH 4/4] net: phy: Use poller for periodic link check Sascha Hauer
2014-09-24  5:09   ` 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=1411024275-31766-2-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