Commit b0b7fa4f authored by Antoine Ténart's avatar Antoine Ténart Committed by David S. Miller

net: mvmdio: introduce an ops structure

Introduce an ops structure to add an indirection on the is_done
function, as this is needed to add the xMDIO support later.
Signed-off-by: default avatarAntoine Tenart <antoine.tenart@free-electrons.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0caf0305
...@@ -62,14 +62,14 @@ struct orion_mdio_dev { ...@@ -62,14 +62,14 @@ struct orion_mdio_dev {
wait_queue_head_t smi_busy_wait; wait_queue_head_t smi_busy_wait;
}; };
static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) struct orion_mdio_ops {
{ int (*is_done)(struct orion_mdio_dev *);
return !(readl(dev->regs) & MVMDIO_SMI_BUSY); };
}
/* Wait for the SMI unit to be ready for another operation /* Wait for the SMI unit to be ready for another operation
*/ */
static int orion_mdio_wait_ready(struct mii_bus *bus) static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops,
struct mii_bus *bus)
{ {
struct orion_mdio_dev *dev = bus->priv; struct orion_mdio_dev *dev = bus->priv;
unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT);
...@@ -77,7 +77,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) ...@@ -77,7 +77,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus)
int timedout = 0; int timedout = 0;
while (1) { while (1) {
if (orion_mdio_smi_is_done(dev)) if (ops->is_done(dev))
return 0; return 0;
else if (timedout) else if (timedout)
break; break;
...@@ -96,8 +96,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) ...@@ -96,8 +96,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus)
if (timeout < 2) if (timeout < 2)
timeout = 2; timeout = 2;
wait_event_timeout(dev->smi_busy_wait, wait_event_timeout(dev->smi_busy_wait,
orion_mdio_smi_is_done(dev), ops->is_done(dev), timeout);
timeout);
++timedout; ++timedout;
} }
...@@ -107,6 +106,15 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) ...@@ -107,6 +106,15 @@ static int orion_mdio_wait_ready(struct mii_bus *bus)
return -ETIMEDOUT; return -ETIMEDOUT;
} }
static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev)
{
return !(readl(dev->regs) & MVMDIO_SMI_BUSY);
}
static const struct orion_mdio_ops orion_mdio_smi_ops = {
.is_done = orion_mdio_smi_is_done,
};
static int orion_mdio_read(struct mii_bus *bus, int mii_id, static int orion_mdio_read(struct mii_bus *bus, int mii_id,
int regnum) int regnum)
{ {
...@@ -114,7 +122,7 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id, ...@@ -114,7 +122,7 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id,
u32 val; u32 val;
int ret; int ret;
ret = orion_mdio_wait_ready(bus); ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -123,7 +131,7 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id, ...@@ -123,7 +131,7 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id,
MVMDIO_SMI_READ_OPERATION), MVMDIO_SMI_READ_OPERATION),
dev->regs); dev->regs);
ret = orion_mdio_wait_ready(bus); ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -145,7 +153,7 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, ...@@ -145,7 +153,7 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id,
struct orion_mdio_dev *dev = bus->priv; struct orion_mdio_dev *dev = bus->priv;
int ret; int ret;
ret = orion_mdio_wait_ready(bus); ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
if (ret < 0) if (ret < 0)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment