phylib: Add Clause 45 read/write functions
authorAndy Fleming <afleming@gmail.com>
Fri, 10 Jan 2014 06:25:09 +0000 (14:25 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 13 Jan 2014 22:29:48 +0000 (14:29 -0800)
Need an extra parameter to read or write Clause 45 PHYs, so
need a different API with the extra parameter.

Signed-off-by: Andy Fleming <afleming@gmail.com>
Signed-off-by: Shaohui Xie <Shaohui.Xie@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/phy.h

index 7c81dd8870d4306a63170efcafb0bd9aba5db46e..3eda43c908751b4eab2abd11b3aae5aa525c8653 100644 (file)
@@ -487,6 +487,24 @@ struct phy_fixup {
        int (*run)(struct phy_device *phydev);
 };
 
+/**
+ * phy_read_mmd - Convenience function for reading a register
+ * from an MMD on a given PHY.
+ * @phydev: The phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: The register on the MMD to read
+ *
+ * Same rules as for phy_read();
+ */
+static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
+{
+       if (!phydev->is_c45)
+               return -EOPNOTSUPP;
+
+       return mdiobus_read(phydev->bus, phydev->addr,
+                           MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff));
+}
+
 /**
  * phy_read - Convenience function for reading a given PHY register
  * @phydev: the phy_device struct
@@ -537,6 +555,27 @@ static inline bool phy_is_internal(struct phy_device *phydev)
        return phydev->is_internal;
 }
 
+/**
+ * phy_write_mmd - Convenience function for writing a register
+ * on an MMD on a given PHY.
+ * @phydev: The phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: The register on the MMD to read
+ * @val: value to write to @regnum
+ *
+ * Same rules as for phy_write();
+ */
+static inline int phy_write_mmd(struct phy_device *phydev, int devad,
+                               u32 regnum, u16 val)
+{
+       if (!phydev->is_c45)
+               return -EOPNOTSUPP;
+
+       regnum = MII_ADDR_C45 | ((devad & 0x1f) << 16) | (regnum & 0xffff);
+
+       return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
+}
+
 struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
                                     bool is_c45,
                                     struct phy_c45_device_ids *c45_ids);
This page took 0.02778 seconds and 5 git commands to generate.