Commit e1dde8dc authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller

net: phy: marvell: Refactor some bigger functions

Break big functions up by using a number of smaller helper
function. Solves some of the over 80 lines warnings, by reducing the
indentation level.
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4f48ed32
...@@ -695,12 +695,11 @@ static int m88e3016_config_init(struct phy_device *phydev) ...@@ -695,12 +695,11 @@ static int m88e3016_config_init(struct phy_device *phydev)
return marvell_config_init(phydev); return marvell_config_init(phydev);
} }
static int m88e1111_config_init(struct phy_device *phydev) static int m88e1111_config_init_rgmii(struct phy_device *phydev)
{ {
int err; int err;
int temp; int temp;
if (phy_interface_is_rgmii(phydev)) {
temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
if (temp < 0) if (temp < 0)
return temp; return temp;
...@@ -730,12 +729,14 @@ static int m88e1111_config_init(struct phy_device *phydev) ...@@ -730,12 +729,14 @@ static int m88e1111_config_init(struct phy_device *phydev)
else else
temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII; temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
if (err < 0) }
return err;
} static int m88e1111_config_init_sgmii(struct phy_device *phydev)
{
int err;
int temp;
if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
if (temp < 0) if (temp < 0)
return temp; return temp;
...@@ -753,16 +754,18 @@ static int m88e1111_config_init(struct phy_device *phydev) ...@@ -753,16 +754,18 @@ static int m88e1111_config_init(struct phy_device *phydev)
if (err < 0) if (err < 0)
return err; return err;
err = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, return phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE, err & (~0xff));
err & (~0xff)); }
if (err < 0)
return err; static int m88e1111_config_init_rtbi(struct phy_device *phydev)
} {
int err;
int temp;
if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
if (temp < 0) if (temp < 0)
return temp; return temp;
temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
if (err < 0) if (err < 0)
...@@ -771,8 +774,11 @@ static int m88e1111_config_init(struct phy_device *phydev) ...@@ -771,8 +774,11 @@ static int m88e1111_config_init(struct phy_device *phydev)
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
if (temp < 0) if (temp < 0)
return temp; return temp;
temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
temp &= ~(MII_M1111_HWCFG_MODE_MASK |
MII_M1111_HWCFG_FIBER_COPPER_RES);
temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO; temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
if (err < 0) if (err < 0)
return err; return err;
...@@ -781,6 +787,7 @@ static int m88e1111_config_init(struct phy_device *phydev) ...@@ -781,6 +787,7 @@ static int m88e1111_config_init(struct phy_device *phydev)
err = phy_write(phydev, MII_BMCR, BMCR_RESET); err = phy_write(phydev, MII_BMCR, BMCR_RESET);
if (err < 0) if (err < 0)
return err; return err;
do do
temp = phy_read(phydev, MII_BMCR); temp = phy_read(phydev, MII_BMCR);
while (temp & BMCR_RESET); while (temp & BMCR_RESET);
...@@ -788,9 +795,33 @@ static int m88e1111_config_init(struct phy_device *phydev) ...@@ -788,9 +795,33 @@ static int m88e1111_config_init(struct phy_device *phydev)
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
if (temp < 0) if (temp < 0)
return temp; return temp;
temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO; temp &= ~(MII_M1111_HWCFG_MODE_MASK |
err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); MII_M1111_HWCFG_FIBER_COPPER_RES);
temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI |
MII_M1111_HWCFG_FIBER_COPPER_AUTO;
return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
}
static int m88e1111_config_init(struct phy_device *phydev)
{
int err;
if (phy_interface_is_rgmii(phydev)) {
err = m88e1111_config_init_rgmii(phydev);
if (err)
return err;
}
if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
err = m88e1111_config_init_sgmii(phydev);
if (err < 0)
return err;
}
if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
err = m88e1111_config_init_rtbi(phydev);
if (err < 0) if (err < 0)
return err; return err;
} }
...@@ -941,29 +972,9 @@ static int m88e1149_config_init(struct phy_device *phydev) ...@@ -941,29 +972,9 @@ static int m88e1149_config_init(struct phy_device *phydev)
return phy_write(phydev, MII_BMCR, BMCR_RESET); return phy_write(phydev, MII_BMCR, BMCR_RESET);
} }
static int m88e1145_config_init(struct phy_device *phydev) static int m88e1145_config_init_rgmii(struct phy_device *phydev)
{ {
int err; int err;
int temp;
/* Take care of errata E0 & E1 */
err = phy_write(phydev, 0x1d, 0x001b);
if (err < 0)
return err;
err = phy_write(phydev, 0x1e, 0x418f);
if (err < 0)
return err;
err = phy_write(phydev, 0x1d, 0x0016);
if (err < 0)
return err;
err = phy_write(phydev, 0x1e, 0xa2da);
if (err < 0)
return err;
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR); int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
if (temp < 0) if (temp < 0)
...@@ -997,13 +1008,14 @@ static int m88e1145_config_init(struct phy_device *phydev) ...@@ -997,13 +1008,14 @@ static int m88e1145_config_init(struct phy_device *phydev)
return err; return err;
err = phy_write(phydev, 0x1e, 0x8000); err = phy_write(phydev, 0x1e, 0x8000);
if (err < 0)
return err;
}
} }
return err;
}
static int m88e1145_config_init_sgmii(struct phy_device *phydev)
{
int temp = phy_read(phydev, MII_M1145_PHY_EXT_SR);
if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
temp = phy_read(phydev, MII_M1145_PHY_EXT_SR);
if (temp < 0) if (temp < 0)
return temp; return temp;
...@@ -1011,7 +1023,38 @@ static int m88e1145_config_init(struct phy_device *phydev) ...@@ -1011,7 +1023,38 @@ static int m88e1145_config_init(struct phy_device *phydev)
temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK; temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK;
temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO; temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO;
err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp); return phy_write(phydev, MII_M1145_PHY_EXT_SR, temp);
}
static int m88e1145_config_init(struct phy_device *phydev)
{
int err;
/* Take care of errata E0 & E1 */
err = phy_write(phydev, 0x1d, 0x001b);
if (err < 0)
return err;
err = phy_write(phydev, 0x1e, 0x418f);
if (err < 0)
return err;
err = phy_write(phydev, 0x1d, 0x0016);
if (err < 0)
return err;
err = phy_write(phydev, 0x1e, 0xa2da);
if (err < 0)
return err;
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
err = m88e1145_config_init_rgmii(phydev);
if (err < 0)
return err;
}
if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
err = m88e1145_config_init_sgmii(phydev);
if (err < 0) if (err < 0)
return err; return err;
} }
...@@ -1072,36 +1115,14 @@ static int marvell_update_link(struct phy_device *phydev, int fiber) ...@@ -1072,36 +1115,14 @@ static int marvell_update_link(struct phy_device *phydev, int fiber)
return 0; return 0;
} }
/* marvell_read_status_page static int marvell_read_status_page_an(struct phy_device *phydev,
* int fiber)
* Description:
* Check the link, then figure out the current state
* by comparing what we advertise with what the link partner
* advertises. Start by checking the gigabit possibilities,
* then move on to 10/100.
*/
static int marvell_read_status_page(struct phy_device *phydev, int page)
{ {
int adv; int status;
int err;
int lpa; int lpa;
int lpagb; int lpagb;
int status = 0; int adv;
int fiber;
/* Detect and update the link, but return if there
* was an error
*/
if (page == MII_M1111_FIBER)
fiber = 1;
else
fiber = 0;
err = marvell_update_link(phydev, fiber);
if (err)
return err;
if (phydev->autoneg == AUTONEG_ENABLE) {
status = phy_read(phydev, MII_M1011_PHY_STATUS); status = phy_read(phydev, MII_M1011_PHY_STATUS);
if (status < 0) if (status < 0)
return status; return status;
...@@ -1144,7 +1165,8 @@ static int marvell_read_status_page(struct phy_device *phydev, int page) ...@@ -1144,7 +1165,8 @@ static int marvell_read_status_page(struct phy_device *phydev, int page)
} }
if (!fiber) { if (!fiber) {
phydev->lp_advertising = mii_stat1000_to_ethtool_lpa_t(lpagb) | phydev->lp_advertising =
mii_stat1000_to_ethtool_lpa_t(lpagb) |
mii_lpa_to_ethtool_lpa_t(lpa); mii_lpa_to_ethtool_lpa_t(lpa);
if (phydev->duplex == DUPLEX_FULL) { if (phydev->duplex == DUPLEX_FULL) {
...@@ -1168,7 +1190,11 @@ static int marvell_read_status_page(struct phy_device *phydev, int page) ...@@ -1168,7 +1190,11 @@ static int marvell_read_status_page(struct phy_device *phydev, int page)
} }
} }
} }
} else { return 0;
}
static int marvell_read_status_page_fixed(struct phy_device *phydev)
{
int bmcr = phy_read(phydev, MII_BMCR); int bmcr = phy_read(phydev, MII_BMCR);
if (bmcr < 0) if (bmcr < 0)
...@@ -1189,11 +1215,43 @@ static int marvell_read_status_page(struct phy_device *phydev, int page) ...@@ -1189,11 +1215,43 @@ static int marvell_read_status_page(struct phy_device *phydev, int page)
phydev->pause = 0; phydev->pause = 0;
phydev->asym_pause = 0; phydev->asym_pause = 0;
phydev->lp_advertising = 0; phydev->lp_advertising = 0;
}
return 0; return 0;
} }
/* marvell_read_status_page
*
* Description:
* Check the link, then figure out the current state
* by comparing what we advertise with what the link partner
* advertises. Start by checking the gigabit possibilities,
* then move on to 10/100.
*/
static int marvell_read_status_page(struct phy_device *phydev, int page)
{
int fiber;
int err;
/* Detect and update the link, but return if there
* was an error
*/
if (page == MII_M1111_FIBER)
fiber = 1;
else
fiber = 0;
err = marvell_update_link(phydev, fiber);
if (err)
return err;
if (phydev->autoneg == AUTONEG_ENABLE)
err = marvell_read_status_page_an(phydev, fiber);
else
err = marvell_read_status_page_fixed(phydev);
return err;
}
/* marvell_read_status /* marvell_read_status
* *
* Some Marvell's phys have two modes: fiber and copper. * Some Marvell's phys have two modes: fiber and copper.
......
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