ar8216: factor out PHY init code into a generic function

PHY init code in the switch-specific hw_init functions is mainly
identical. Factor it out into a generic ar8xxx_phy_init function.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 43331
lede-17.01
Felix Fietkau 2014-11-19 20:17:52 +00:00
parent 20baeb5595
commit 898712f43f
1 changed files with 25 additions and 41 deletions

View File

@ -342,6 +342,28 @@ ar8xxx_phy_poll_reset(struct mii_bus *bus)
return -ETIMEDOUT; return -ETIMEDOUT;
} }
static void
ar8xxx_phy_init(struct ar8xxx_priv *priv, bool support_1000)
{
int i;
struct mii_bus *bus;
if (priv->chip->fixup_phys)
priv->chip->fixup_phys(priv);
bus = priv->mii_bus;
for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
/* initialize the port itself */
mdiobus_write(bus, i, MII_ADVERTISE,
ADVERTISE_ALL | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
if (support_1000)
mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
}
ar8xxx_phy_poll_reset(bus);
}
static u32 static u32
ar8xxx_mii_read(struct ar8xxx_priv *priv, int reg) ar8xxx_mii_read(struct ar8xxx_priv *priv, int reg)
{ {
@ -888,22 +910,10 @@ ar8236_setup_port(struct ar8xxx_priv *priv, int port, u32 members)
static int static int
ar8236_hw_init(struct ar8xxx_priv *priv) ar8236_hw_init(struct ar8xxx_priv *priv)
{ {
int i;
struct mii_bus *bus;
if (priv->initialized) if (priv->initialized)
return 0; return 0;
/* Initialize the PHYs */ ar8xxx_phy_init(priv, false);
bus = priv->mii_bus;
for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
mdiobus_write(bus, i, MII_ADVERTISE,
ADVERTISE_ALL | ADVERTISE_PAUSE_CAP |
ADVERTISE_PAUSE_ASYM);
mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
}
ar8xxx_phy_poll_reset(bus);
priv->initialized = true; priv->initialized = true;
return 0; return 0;
@ -940,9 +950,7 @@ static const struct ar8xxx_chip ar8236_chip = {
static int static int
ar8316_hw_init(struct ar8xxx_priv *priv) ar8316_hw_init(struct ar8xxx_priv *priv)
{ {
int i;
u32 val, newval; u32 val, newval;
struct mii_bus *bus;
val = priv->read(priv, AR8316_REG_POSTRIP); val = priv->read(priv, AR8316_REG_POSTRIP);
@ -981,17 +989,7 @@ ar8316_hw_init(struct ar8xxx_priv *priv)
msleep(1000); msleep(1000);
} }
/* Initialize the ports */ ar8xxx_phy_init(priv, true);
bus = priv->mii_bus;
for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
/* initialize the port itself */
mdiobus_write(bus, i, MII_ADVERTISE,
ADVERTISE_ALL | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
}
ar8xxx_phy_poll_reset(bus);
out: out:
priv->initialized = true; priv->initialized = true;
@ -1622,9 +1620,7 @@ ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
static int static int
ar8327_hw_init(struct ar8xxx_priv *priv) ar8327_hw_init(struct ar8xxx_priv *priv)
{ {
struct mii_bus *bus;
int ret; int ret;
int i;
if (priv->phy->dev.of_node) if (priv->phy->dev.of_node)
ret = ar8327_hw_config_of(priv, priv->phy->dev.of_node); ret = ar8327_hw_config_of(priv, priv->phy->dev.of_node);
@ -1637,19 +1633,7 @@ ar8327_hw_init(struct ar8xxx_priv *priv)
ar8327_leds_init(priv); ar8327_leds_init(priv);
priv->chip->fixup_phys(priv); ar8xxx_phy_init(priv, true);
bus = priv->mii_bus;
for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
/* start aneg on the PHY */
mdiobus_write(bus, i, MII_ADVERTISE, ADVERTISE_ALL |
ADVERTISE_PAUSE_CAP |
ADVERTISE_PAUSE_ASYM);
mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
}
ar8xxx_phy_poll_reset(bus);
return 0; return 0;
} }