Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 300508
b: refs/heads/master
c: 39b401d
h: refs/heads/master
v: v3
  • Loading branch information
Deepak SIKRI authored and David S. Miller committed Apr 4, 2012
1 parent 0a09b1c commit b6e91f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8327eb65e795ba4f922bf7e531cd312875f0dc29
refs/heads/master: 39b401dbd3a36f04657afa078d1d25278a26e9c9
32 changes: 25 additions & 7 deletions trunk/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
#define MII_BUSY 0x00000001
#define MII_WRITE 0x00000002

static int stmmac_mdio_busy_wait(void __iomem *ioaddr, unsigned int mii_addr)
{
unsigned long curr;
unsigned long finish = jiffies + 3 * HZ;

do {
curr = jiffies;
if (readl(ioaddr + mii_addr) & MII_BUSY)
cpu_relax();
else
return 0;
} while (!time_after_eq(curr, finish));

return -EBUSY;
}

/**
* stmmac_mdio_read
* @bus: points to the mii_bus structure
Expand All @@ -56,9 +72,13 @@ static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg)
((phyreg << 6) & (0x000007C0)));
regValue |= MII_BUSY | ((priv->plat->clk_csr & 7) << 2);

do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);
if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
return -EBUSY;

writel(regValue, priv->ioaddr + mii_address);
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);

if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
return -EBUSY;

/* Read the data from the MII data register */
data = (int)readl(priv->ioaddr + mii_data);
Expand Down Expand Up @@ -88,18 +108,16 @@ static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg,

value |= MII_BUSY | ((priv->plat->clk_csr & 7) << 2);


/* Wait until any existing MII operation is complete */
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);
if (stmmac_mdio_busy_wait(priv->ioaddr, mii_address))
return -EBUSY;

/* Set the MII address register to write */
writel(phydata, priv->ioaddr + mii_data);
writel(value, priv->ioaddr + mii_address);

/* Wait until any existing MII operation is complete */
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);

return 0;
return stmmac_mdio_busy_wait(priv->ioaddr, mii_address);
}

/**
Expand Down

0 comments on commit b6e91f2

Please sign in to comment.