The ADIN1200 & ADIN1300 PHYs support EEE by using standard Clause 45 access to access MMD registers for EEE. The EEE register addresses (when using Clause 22) are available at different addresses (than Clause 45), and since accessing these regs (via Clause 22) needs a special mechanism, a translation table is required to convert these addresses. For Clause 45, this is not needed; the addresses are available as specified by IEEE. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@xxxxxxxxxx> --- drivers/net/phy/adin.c | 61 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c index 31c600b7ec66..3c559a3ba487 100644 --- a/drivers/net/phy/adin.c +++ b/drivers/net/phy/adin.c @@ -44,6 +44,17 @@ #define ADIN1300_PHY_STATUS1 0x001a #define ADIN1300_PAIR_01_SWAP BIT(11) +/* EEE register addresses, accessible via Clause 22 access using + * ADIN1300_MII_EXT_REG_PTR & ADIN1300_MII_EXT_REG_DATA. + * The bit-fields are the same as specified by IEEE, and can be + * accessed via standard Clause 45 access. + */ +#define ADIN1300_EEE_CAP_REG 0x8000 +#define ADIN1300_EEE_ADV_REG 0x8001 +#define ADIN1300_EEE_LPABLE_REG 0x8002 +#define ADIN1300_CLOCK_STOP_REG 0x9400 +#define ADIN1300_LPI_WAKE_ERR_CNT_REG 0xa000 + #define ADIN1300_GE_RGMII_CFG_REG 0xff23 #define ADIN1300_GE_RGMII_RX_MSK GENMASK(8, 6) #define ADIN1300_GE_RGMII_RX_SEL(x) \ @@ -61,6 +72,20 @@ FIELD_PREP(ADIN1300_GE_RMII_FIFO_DEPTH_MSK, x) #define ADIN1300_GE_RMII_EN BIT(0) +struct clause22_mmd_map { + int devad; + u16 cl22_regnum; + u16 adin_regnum; +}; + +static struct clause22_mmd_map clause22_mmd_map[] = { + { MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE, ADIN1300_EEE_CAP_REG }, + { MDIO_MMD_AN, MDIO_AN_EEE_LPABLE, ADIN1300_EEE_LPABLE_REG }, + { MDIO_MMD_AN, MDIO_AN_EEE_ADV, ADIN1300_EEE_ADV_REG }, + { MDIO_MMD_PCS, MDIO_CTRL1, ADIN1300_CLOCK_STOP_REG }, + { MDIO_MMD_PCS, MDIO_PCS_EEE_WK_ERR, ADIN1300_LPI_WAKE_ERR_CNT_REG }, +}; + static int adin_get_phy_internal_mode(struct phy_device *phydev) { struct device *dev = &phydev->mdio.dev; @@ -233,10 +258,31 @@ static int adin_phy_config_intr(struct phy_device *phydev) ADIN1300_INT_MASK_EN); } +static int adin_cl22_to_adin_reg(int devad, u16 cl22_regnum) +{ + struct clause22_mmd_map *m; + int i; + + if (devad == MDIO_MMD_VEND1) + return cl22_regnum; + + for (i = 0; i < ARRAY_SIZE(clause22_mmd_map); i++) { + m = &clause22_mmd_map[i]; + if (m->devad == devad && m->cl22_regnum == cl22_regnum) + return m->adin_regnum; + } + + pr_err("No translation available for devad: %d reg: %04x\n", + devad, cl22_regnum); + + return -EINVAL; +} + static int adin_read_mmd(struct phy_device *phydev, int devad, u16 regnum) { struct mii_bus *bus = phydev->mdio.bus; int phy_addr = phydev->mdio.addr; + int adin_regnum; int err; if (phydev->is_c45) { @@ -245,7 +291,12 @@ static int adin_read_mmd(struct phy_device *phydev, int devad, u16 regnum) return __mdiobus_read(bus, phy_addr, addr); } - err = __mdiobus_write(bus, phy_addr, ADIN1300_MII_EXT_REG_PTR, regnum); + adin_regnum = adin_cl22_to_adin_reg(devad, regnum); + if (adin_regnum < 0) + return adin_regnum; + + err = __mdiobus_write(bus, phy_addr, ADIN1300_MII_EXT_REG_PTR, + adin_regnum); if (err) return err; @@ -257,6 +308,7 @@ static int adin_write_mmd(struct phy_device *phydev, int devad, u16 regnum, { struct mii_bus *bus = phydev->mdio.bus; int phy_addr = phydev->mdio.addr; + int adin_regnum; int err; if (phydev->is_c45) { @@ -265,7 +317,12 @@ static int adin_write_mmd(struct phy_device *phydev, int devad, u16 regnum, return __mdiobus_write(bus, phy_addr, addr, val); } - err = __mdiobus_write(bus, phy_addr, ADIN1300_MII_EXT_REG_PTR, regnum); + adin_regnum = adin_cl22_to_adin_reg(devad, regnum); + if (adin_regnum < 0) + return adin_regnum; + + err = __mdiobus_write(bus, phy_addr, ADIN1300_MII_EXT_REG_PTR, + adin_regnum); if (err) return err; -- 2.20.1