public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] arm:kirkwood Wait for the link to come up on kirkwood network init
@ 2009-08-19 10:24 Simon Kagstrom
  2009-08-19 17:08 ` Ben Warren
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Kagstrom @ 2009-08-19 10:24 UTC (permalink / raw)
  To: u-boot

Wait for the link to come up on kirkwood network init

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).

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

diff --git a/drivers/net/kirkwood_egiga.c b/drivers/net/kirkwood_egiga.c
index f31fefc..9ac9c1f 100644
--- a/drivers/net/kirkwood_egiga.c
+++ b/drivers/net/kirkwood_egiga.c
@@ -396,6 +396,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);
@@ -443,12 +444,18 @@ 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, 0xEE, 0xEE, &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, 0xEE, 0xEE, &phyadr);
+		/* Return if we get link up */
+		if (miiphy_link(dev->name, phyadr))
+			return 0;
+		udelay(1000000);
 	}
+
+	printf("%s: No link on %s\n", __FUNCTION__, dev->name);
+	return -1;
 #endif
 	return 0;
 }
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-08-20  7:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-19 10:24 [U-Boot] [PATCH] arm:kirkwood Wait for the link to come up on kirkwood network init Simon Kagstrom
2009-08-19 17:08 ` Ben Warren
2009-08-19 19:25   ` Wolfgang Denk
2009-08-19 19:29     ` Ben Warren
2009-08-19 19:40       ` Wolfgang Denk
2009-08-20  7:51   ` Simon Kagstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox