net: dsa: mv88e6xxx: Add EEE support
authorGuenter Roeck <linux@roeck-us.net>
Sat, 7 Mar 2015 06:23:51 +0000 (22:23 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 8 Mar 2015 03:34:10 +0000 (22:34 -0500)
EEE configuration is similar for the various MV88E6xxx chips.
Add generic support for it.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx.c
drivers/net/dsa/mv88e6xxx.h

index a83ace0803e79638d510ab8d2024a9dbcc0e055d..c18ffc98aaccf126874590630484912cc5dd47ae 100644 (file)
@@ -649,6 +649,57 @@ int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
        return mv88e6xxx_phy_wait(ds);
 }
 
+int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
+{
+       int reg;
+
+       reg = mv88e6xxx_phy_read_indirect(ds, port, 16);
+       if (reg < 0)
+               return -EOPNOTSUPP;
+
+       e->eee_enabled = !!(reg & 0x0200);
+       e->tx_lpi_enabled = !!(reg & 0x0100);
+
+       reg = REG_READ(REG_PORT(port), 0);
+       e->eee_active = !!(reg & 0x0040);
+
+       return 0;
+}
+
+static int mv88e6xxx_eee_enable_set(struct dsa_switch *ds, int port,
+                                   bool eee_enabled, bool tx_lpi_enabled)
+{
+       int reg, nreg;
+
+       reg = mv88e6xxx_phy_read_indirect(ds, port, 16);
+       if (reg < 0)
+               return reg;
+
+       nreg = reg & ~0x0300;
+       if (eee_enabled)
+               nreg |= 0x0200;
+       if (tx_lpi_enabled)
+               nreg |= 0x0100;
+
+       if (nreg != reg)
+               return mv88e6xxx_phy_write_indirect(ds, port, 16, nreg);
+
+       return 0;
+}
+
+int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
+                     struct phy_device *phydev, struct ethtool_eee *e)
+{
+       int ret;
+
+       ret = mv88e6xxx_eee_enable_set(ds, port, e->eee_enabled,
+                                      e->tx_lpi_enabled);
+       if (ret)
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
 static int __init mv88e6xxx_init(void)
 {
 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
index 72942271bb67ed988484e09c780a3ae46e54251c..5fd42ced90117c741c192bed8b03d71f060c9943 100644 (file)
@@ -88,6 +88,9 @@ int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
 int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
 int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
                                 u16 val);
+int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
+int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
+                     struct phy_device *phydev, struct ethtool_eee *e);
 
 extern struct dsa_switch_driver mv88e6131_switch_driver;
 extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;