Commit aec128f9 authored by David S. Miller's avatar David S. Miller

Merge branch 'marvell10g-tunable-and-power-saving-support'

Russell King says:

====================
marvell10g tunable and power saving support

This patch series adds support for:
- mdix configuration (auto, mdi, mdix)
- energy detect power down (edpd)
- placing in edpd mode at probe

for both the 88x3310 and 88x2110 PHYs.

Antione, could you test this for the 88x2110 PHY please?

v3: fix return code in get_tunable/set_tunable
v2: fix comments from Antione.
====================
Tested-by: default avatarAntoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents e7c29885 c9cc1c81
......@@ -23,6 +23,7 @@
* link takes priority and the other port is completely locked out.
*/
#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/hwmon.h>
#include <linux/marvell_phy.h>
#include <linux/phy.h>
......@@ -39,6 +40,16 @@ enum {
MV_PCS_BASE_R = 0x1000,
MV_PCS_1000BASEX = 0x2000,
MV_PCS_CSCR1 = 0x8000,
MV_PCS_CSCR1_ED_MASK = 0x0300,
MV_PCS_CSCR1_ED_OFF = 0x0000,
MV_PCS_CSCR1_ED_RX = 0x0200,
MV_PCS_CSCR1_ED_NLP = 0x0300,
MV_PCS_CSCR1_MDIX_MASK = 0x0060,
MV_PCS_CSCR1_MDIX_MDI = 0x0000,
MV_PCS_CSCR1_MDIX_MDIX = 0x0020,
MV_PCS_CSCR1_MDIX_AUTO = 0x0060,
MV_PCS_CSSR1 = 0x8008,
MV_PCS_CSSR1_SPD1_MASK = 0xc000,
MV_PCS_CSSR1_SPD1_SPD2 = 0xc000,
......@@ -216,6 +227,91 @@ static int mv3310_hwmon_probe(struct phy_device *phydev)
}
#endif
static int mv3310_power_down(struct phy_device *phydev)
{
return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
MV_V2_PORT_CTRL_PWRDOWN);
}
static int mv3310_power_up(struct phy_device *phydev)
{
return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
MV_V2_PORT_CTRL_PWRDOWN);
}
static int mv3310_reset(struct phy_device *phydev, u32 unit)
{
int retries, val, err;
err = phy_modify_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1,
MDIO_CTRL1_RESET, MDIO_CTRL1_RESET);
if (err < 0)
return err;
retries = 20;
do {
msleep(5);
val = phy_read_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1);
if (val < 0)
return val;
} while (val & MDIO_CTRL1_RESET && --retries);
return val & MDIO_CTRL1_RESET ? -ETIMEDOUT : 0;
}
static int mv3310_get_edpd(struct phy_device *phydev, u16 *edpd)
{
int val;
val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1);
if (val < 0)
return val;
switch (val & MV_PCS_CSCR1_ED_MASK) {
case MV_PCS_CSCR1_ED_NLP:
*edpd = 1000;
break;
case MV_PCS_CSCR1_ED_RX:
*edpd = ETHTOOL_PHY_EDPD_NO_TX;
break;
default:
*edpd = ETHTOOL_PHY_EDPD_DISABLE;
break;
}
return 0;
}
static int mv3310_set_edpd(struct phy_device *phydev, u16 edpd)
{
u16 val;
int err;
switch (edpd) {
case 1000:
case ETHTOOL_PHY_EDPD_DFLT_TX_MSECS:
val = MV_PCS_CSCR1_ED_NLP;
break;
case ETHTOOL_PHY_EDPD_NO_TX:
val = MV_PCS_CSCR1_ED_RX;
break;
case ETHTOOL_PHY_EDPD_DISABLE:
val = MV_PCS_CSCR1_ED_OFF;
break;
default:
return -EINVAL;
}
err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1,
MV_PCS_CSCR1_ED_MASK, val);
if (err > 0)
err = mv3310_reset(phydev, MV_PCS_BASE_T);
return err;
}
static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
{
struct phy_device *phydev = upstream;
......@@ -264,6 +360,11 @@ static int mv3310_probe(struct phy_device *phydev)
dev_set_drvdata(&phydev->mdio.dev, priv);
/* Powering down the port when not in use saves about 600mW */
ret = mv3310_power_down(phydev);
if (ret)
return ret;
ret = mv3310_hwmon_probe(phydev);
if (ret)
return ret;
......@@ -273,16 +374,14 @@ static int mv3310_probe(struct phy_device *phydev)
static int mv3310_suspend(struct phy_device *phydev)
{
return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
MV_V2_PORT_CTRL_PWRDOWN);
return mv3310_power_down(phydev);
}
static int mv3310_resume(struct phy_device *phydev)
{
int ret;
ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
MV_V2_PORT_CTRL_PWRDOWN);
ret = mv3310_power_up(phydev);
if (ret)
return ret;
......@@ -308,6 +407,8 @@ static bool mv3310_has_pma_ngbaset_quirk(struct phy_device *phydev)
static int mv3310_config_init(struct phy_device *phydev)
{
int err;
/* Check that the PHY interface type is compatible */
if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
phydev->interface != PHY_INTERFACE_MODE_2500BASEX &&
......@@ -316,7 +417,15 @@ static int mv3310_config_init(struct phy_device *phydev)
phydev->interface != PHY_INTERFACE_MODE_10GBASER)
return -ENODEV;
return 0;
phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
/* Power up so reset works */
err = mv3310_power_up(phydev);
if (err)
return err;
/* Enable EDPD mode - saving 600mW */
return mv3310_set_edpd(phydev, ETHTOOL_PHY_EDPD_DFLT_TX_MSECS);
}
static int mv3310_get_features(struct phy_device *phydev)
......@@ -345,14 +454,42 @@ static int mv3310_get_features(struct phy_device *phydev)
return 0;
}
static int mv3310_config_mdix(struct phy_device *phydev)
{
u16 val;
int err;
switch (phydev->mdix_ctrl) {
case ETH_TP_MDI_AUTO:
val = MV_PCS_CSCR1_MDIX_AUTO;
break;
case ETH_TP_MDI_X:
val = MV_PCS_CSCR1_MDIX_MDIX;
break;
case ETH_TP_MDI:
val = MV_PCS_CSCR1_MDIX_MDI;
break;
default:
return -EINVAL;
}
err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1,
MV_PCS_CSCR1_MDIX_MASK, val);
if (err > 0)
err = mv3310_reset(phydev, MV_PCS_BASE_T);
return err;
}
static int mv3310_config_aneg(struct phy_device *phydev)
{
bool changed = false;
u16 reg;
int ret;
/* We don't support manual MDI control */
phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
ret = mv3310_config_mdix(phydev);
if (ret < 0)
return ret;
if (phydev->autoneg == AUTONEG_DISABLE)
return genphy_c45_pma_setup_forced(phydev);
......@@ -537,6 +674,28 @@ static int mv3310_read_status(struct phy_device *phydev)
return 0;
}
static int mv3310_get_tunable(struct phy_device *phydev,
struct ethtool_tunable *tuna, void *data)
{
switch (tuna->id) {
case ETHTOOL_PHY_EDPD:
return mv3310_get_edpd(phydev, data);
default:
return -EOPNOTSUPP;
}
}
static int mv3310_set_tunable(struct phy_device *phydev,
struct ethtool_tunable *tuna, const void *data)
{
switch (tuna->id) {
case ETHTOOL_PHY_EDPD:
return mv3310_set_edpd(phydev, *(u16 *)data);
default:
return -EOPNOTSUPP;
}
}
static struct phy_driver mv3310_drivers[] = {
{
.phy_id = MARVELL_PHY_ID_88X3310,
......@@ -551,6 +710,8 @@ static struct phy_driver mv3310_drivers[] = {
.config_aneg = mv3310_config_aneg,
.aneg_done = mv3310_aneg_done,
.read_status = mv3310_read_status,
.get_tunable = mv3310_get_tunable,
.set_tunable = mv3310_set_tunable,
},
{
.phy_id = MARVELL_PHY_ID_88E2110,
......@@ -564,6 +725,8 @@ static struct phy_driver mv3310_drivers[] = {
.config_aneg = mv3310_config_aneg,
.aneg_done = mv3310_aneg_done,
.read_status = mv3310_read_status,
.get_tunable = mv3310_get_tunable,
.set_tunable = mv3310_set_tunable,
},
};
......
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