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

net: phy: marvell: Consolidate setting the phy-mode

The same code is repeated a few times. Refactor into a helped.
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 61111598
...@@ -60,11 +60,6 @@ ...@@ -60,11 +60,6 @@
#define MII_M1011_PHY_SCR_MDI_X 0x0020 #define MII_M1011_PHY_SCR_MDI_X 0x0020
#define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060 #define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
#define MII_M1145_PHY_EXT_SR 0x1b
#define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
#define MII_M1145_HWCFG_MODE_MASK 0xf
#define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
#define MII_M1111_PHY_LED_CONTROL 0x18 #define MII_M1111_PHY_LED_CONTROL 0x18
#define MII_M1111_PHY_LED_DIRECT 0x4100 #define MII_M1111_PHY_LED_DIRECT 0x4100
#define MII_M1111_PHY_LED_COMBINE 0x411c #define MII_M1111_PHY_LED_COMBINE 0x411c
...@@ -74,12 +69,13 @@ ...@@ -74,12 +69,13 @@
#define MII_M1111_PHY_EXT_SR 0x1b #define MII_M1111_PHY_EXT_SR 0x1b
#define MII_M1111_HWCFG_MODE_MASK 0xf #define MII_M1111_HWCFG_MODE_MASK 0xf
#define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
#define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3 #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
#define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4 #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
#define MII_M1111_HWCFG_MODE_RTBI 0x7
#define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9 #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
#define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000 #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
#define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000 #define MII_M1111_HWCFG_FIBER_COPPER_RES BIT(13)
#define MII_M1111_HWCFG_FIBER_COPPER_AUTO BIT(15)
#define MII_88E1121_PHY_MSCR_REG 21 #define MII_88E1121_PHY_MSCR_REG 21
#define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5) #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
...@@ -693,6 +689,27 @@ static int m88e3016_config_init(struct phy_device *phydev) ...@@ -693,6 +689,27 @@ static int m88e3016_config_init(struct phy_device *phydev)
return marvell_config_init(phydev); return marvell_config_init(phydev);
} }
static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev,
u16 mode,
int fibre_copper_auto)
{
int temp;
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
if (temp < 0)
return temp;
temp &= ~(MII_M1111_HWCFG_MODE_MASK |
MII_M1111_HWCFG_FIBER_COPPER_AUTO |
MII_M1111_HWCFG_FIBER_COPPER_RES);
temp |= mode;
if (fibre_copper_auto)
temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
}
static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev) static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev)
{ {
int temp; int temp;
...@@ -740,17 +757,11 @@ static int m88e1111_config_init_rgmii(struct phy_device *phydev) ...@@ -740,17 +757,11 @@ static int m88e1111_config_init_rgmii(struct phy_device *phydev)
static int m88e1111_config_init_sgmii(struct phy_device *phydev) static int m88e1111_config_init_sgmii(struct phy_device *phydev)
{ {
int err; int err;
int temp;
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); err = m88e1111_config_init_hwcfg_mode(
if (temp < 0) phydev,
return temp; MII_M1111_HWCFG_MODE_SGMII_NO_CLK,
MII_M1111_HWCFG_FIBER_COPPER_AUTO);
temp &= ~(MII_M1111_HWCFG_MODE_MASK);
temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK;
temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
if (err < 0) if (err < 0)
return err; return err;
...@@ -760,22 +771,16 @@ static int m88e1111_config_init_sgmii(struct phy_device *phydev) ...@@ -760,22 +771,16 @@ static int m88e1111_config_init_sgmii(struct phy_device *phydev)
static int m88e1111_config_init_rtbi(struct phy_device *phydev) static int m88e1111_config_init_rtbi(struct phy_device *phydev)
{ {
int temp;
int err; int err;
err = m88e1111_config_init_rgmii_delays(phydev); err = m88e1111_config_init_rgmii_delays(phydev);
if (err) if (err)
return err; return err;
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); err = m88e1111_config_init_hwcfg_mode(
if (temp < 0) phydev,
return temp; MII_M1111_HWCFG_MODE_RTBI,
MII_M1111_HWCFG_FIBER_COPPER_AUTO);
temp &= ~(MII_M1111_HWCFG_MODE_MASK |
MII_M1111_HWCFG_FIBER_COPPER_RES);
temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
if (err < 0) if (err < 0)
return err; return err;
...@@ -784,16 +789,10 @@ static int m88e1111_config_init_rtbi(struct phy_device *phydev) ...@@ -784,16 +789,10 @@ static int m88e1111_config_init_rtbi(struct phy_device *phydev)
if (err < 0) if (err < 0)
return err; return err;
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); return m88e1111_config_init_hwcfg_mode(
if (temp < 0) phydev,
return temp; MII_M1111_HWCFG_MODE_RTBI,
MII_M1111_HWCFG_FIBER_COPPER_AUTO);
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;
return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
} }
static int m88e1111_config_init(struct phy_device *phydev) static int m88e1111_config_init(struct phy_device *phydev)
...@@ -999,16 +998,9 @@ static int m88e1145_config_init_rgmii(struct phy_device *phydev) ...@@ -999,16 +998,9 @@ static int m88e1145_config_init_rgmii(struct phy_device *phydev)
static int m88e1145_config_init_sgmii(struct phy_device *phydev) static int m88e1145_config_init_sgmii(struct phy_device *phydev)
{ {
int temp = phy_read(phydev, MII_M1145_PHY_EXT_SR); return m88e1111_config_init_hwcfg_mode(
phydev, MII_M1111_HWCFG_MODE_SGMII_NO_CLK,
if (temp < 0) MII_M1111_HWCFG_FIBER_COPPER_AUTO);
return temp;
temp &= ~MII_M1145_HWCFG_MODE_MASK;
temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK;
temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO;
return phy_write(phydev, MII_M1145_PHY_EXT_SR, temp);
} }
static int m88e1145_config_init(struct phy_device *phydev) static int m88e1145_config_init(struct phy_device *phydev)
......
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