public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Kagstrom <simon.kagstrom@netinsight.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/3]: Wait for the link to come up on kirkwood network init
Date: Thu, 20 Aug 2009 10:13:06 +0200	[thread overview]
Message-ID: <20090820101306.08ee72b2@marrow.netinsight.se> (raw)
In-Reply-To: <20090820101142.6474a0fc@marrow.netinsight.se>

This patch makes the device wait for up to 5 seconds for the link to
come up, similar to what many of the other network drivers do. This
avoids confusing situations where, e.g., a tftp fails when initiated
early after U-boot has started (before the link has come up).

v2: Remove function name from printout

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 drivers/net/kirkwood_egiga.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/net/kirkwood_egiga.c b/drivers/net/kirkwood_egiga.c
index 065e335..9f36633 100644
--- a/drivers/net/kirkwood_egiga.c
+++ b/drivers/net/kirkwood_egiga.c
@@ -400,6 +400,7 @@ static int kwgbe_init(struct eth_device *dev)
 {
 	struct kwgbe_device *dkwgbe = to_dkwgbe(dev);
 	struct kwgbe_registers *regs = dkwgbe->regs;
+	int i;
 
 	/* setup RX rings */
 	kwgbe_init_rx_desc_ring(dkwgbe);
@@ -447,13 +448,20 @@ static int kwgbe_init(struct eth_device *dev)
 
 #if (defined (CONFIG_MII) || defined (CONFIG_CMD_MII)) \
 	 && defined (CONFIG_SYS_FAULT_ECHO_LINK_DOWN)
-	u16 phyadr;
-	miiphy_read(dev->name, KIRKWOOD_PHY_ADR_REQUEST,
-			KIRKWOOD_PHY_ADR_REQUEST, &phyadr);
-	if (!miiphy_link(dev->name, phyadr)) {
-		printf("%s: No link on %s\n", __FUNCTION__, dev->name);
-		return -1;
+	/* Wait up to 5s for the link status */
+	for (i = 0; i < 5; i++) {
+		u16 phyadr;
+
+		miiphy_read(dev->name, KIRKWOOD_PHY_ADR_REQUEST,
+				KIRKWOOD_PHY_ADR_REQUEST, &phyadr);
+		/* Return if we get link up */
+		if (miiphy_link(dev->name, phyadr))
+			return 0;
+		udelay(1000000);
 	}
+
+	printf("No link on %s\n", dev->name);
+	return -1;
 #endif
 	return 0;
 }
-- 
1.6.0.4

  parent reply	other threads:[~2009-08-20  8:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-20  8:11 [U-Boot] [PATCH 0/3]: arm:Kirkwood network driver fixes Simon Kagstrom
2009-08-20  8:12 ` [U-Boot] [PATCH 1/3]: arm:kirkwood Define kirkwood phy address magic number Simon Kagstrom
2009-08-20  9:40   ` Prafulla Wadaskar
2009-08-20 11:47     ` Simon Kagstrom
2009-08-21  3:20       ` Prafulla Wadaskar
2009-08-21  8:52         ` Simon Kagstrom
2009-08-21 16:59   ` Ben Warren
2009-08-20  8:13 ` Simon Kagstrom [this message]
2009-08-20  8:14 ` [U-Boot] [PATCH 3/3] [repost]: arm: kirkwood: See to it that sent data is 8-byte aligned Simon Kagstrom
2009-08-20  9:25   ` Prafulla Wadaskar

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=20090820101306.08ee72b2@marrow.netinsight.se \
    --to=simon.kagstrom@netinsight.net \
    --cc=u-boot@lists.denx.de \
    /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