summaryrefslogtreecommitdiff
path: root/drivers/net/phy
diff options
context:
space:
mode:
authorFlorian Fainelli <f.fainelli@gmail.com>2017-07-31 12:04:22 -0700
committerDavid S. Miller <davem@davemloft.net>2017-07-31 14:40:58 -0700
commit69a60b0579a4bf63871dfcfaca44a4e20c7d05f8 (patch)
tree37a14f835157257dece61b2c05fb70ecebd65275 /drivers/net/phy
parent834e0ecf8109ee92184b9616bdc3aca6fe934f38 (diff)
net: phy: mdio-bcm-unimac: factor busy polling loop
Factor the code that does the busy polling on the MDIO_BUSY bit since we will have different code-paths for for completion depending on whether we are using interrupts or polling. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy')
-rw-r--r--drivers/net/phy/mdio-bcm-unimac.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/drivers/net/phy/mdio-bcm-unimac.c b/drivers/net/phy/mdio-bcm-unimac.c
index 34395230ce70..226fdccfa1a8 100644
--- a/drivers/net/phy/mdio-bcm-unimac.c
+++ b/drivers/net/phy/mdio-bcm-unimac.c
@@ -57,10 +57,26 @@ static inline unsigned int unimac_mdio_busy(struct unimac_mdio_priv *priv)
return __raw_readl(priv->base + MDIO_CMD) & MDIO_START_BUSY;
}
+static int unimac_mdio_poll(struct unimac_mdio_priv *priv)
+{
+ unsigned int timeout = 1000;
+
+ do {
+ if (!unimac_mdio_busy(priv))
+ return 0;
+
+ usleep_range(1000, 2000);
+ } while (timeout--);
+
+ if (!timeout)
+ return -ETIMEDOUT;
+
+ return 0;
+}
+
static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
{
struct unimac_mdio_priv *priv = bus->priv;
- unsigned int timeout = 1000;
u32 cmd;
/* Prepare the read operation */
@@ -70,15 +86,9 @@ static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
/* Start MDIO transaction */
unimac_mdio_start(priv);
- do {
- if (!unimac_mdio_busy(priv))
- break;
-
- usleep_range(1000, 2000);
- } while (timeout--);
-
- if (!timeout)
- return -ETIMEDOUT;
+ ret = unimac_mdio_poll(priv);
+ if (ret)
+ return ret;
cmd = __raw_readl(priv->base + MDIO_CMD);
@@ -97,7 +107,6 @@ static int unimac_mdio_write(struct mii_bus *bus, int phy_id,
int reg, u16 val)
{
struct unimac_mdio_priv *priv = bus->priv;
- unsigned int timeout = 1000;
u32 cmd;
/* Prepare the write operation */
@@ -107,17 +116,7 @@ static int unimac_mdio_write(struct mii_bus *bus, int phy_id,
unimac_mdio_start(priv);
- do {
- if (!unimac_mdio_busy(priv))
- break;
-
- usleep_range(1000, 2000);
- } while (timeout--);
-
- if (!timeout)
- return -ETIMEDOUT;
-
- return 0;
+ return unimac_mdio_poll(priv);
}
/* Workaround for integrated BCM7xxx Gigabit PHYs which have a problem with