[PATCH 3/3] net: miidev: properly check for MII reset

Wolfram Sang w.sang at pengutronix.de
Wed Mar 21 07:18:45 EDT 2012


Wait until the reset bit is actually cleared instead of some
arbitrary delay (which caused problems with a PHY which was in some
energy saving mode).

Signed-off-by: Wolfram Sang <w.sang at pengutronix.de>
---
 drivers/net/miidev.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index 16a3461..3b73133 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -31,19 +31,26 @@
 int miidev_restart_aneg(struct mii_device *mdev)
 {
 	int status, timeout;
+	uint64_t start;
 
-	/*
-	 * Reset PHY, then delay 300ns
-	 */
 	status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_RESET);
 	if (status)
 		return status;
 
+	start = get_time_ns();
+	do {
+		status = mii_read(mdev, mdev->address, MII_BMCR);
+		if (status < 0)
+			return status;
+
+		if (is_timeout(start, SECOND))
+			return -ETIMEDOUT;
+
+	} while (status & BMCR_RESET);
+
 	if (mdev->flags & MIIDEV_FORCE_LINK)
 		return 0;
 
-	udelay(1000);
-
 	if (mdev->flags & MIIDEV_FORCE_10) {
 		printf("Forcing 10 Mbps ethernet link... ");
 
-- 
1.7.9.1




More information about the barebox mailing list