diff options
author | Dan Murphy <dmurphy@ti.com> | 2020-05-04 16:14:38 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-06-12 13:17:23 -0400 |
commit | 535247a9e455a165943efcdbb7e144e816d6e904 (patch) | |
tree | 04138f57048d3189eb3d6901f30381f0f5208220 /include/phy.h | |
parent | ea756fb8b71f5399c10f4a8f7e4325ced90d7c9f (diff) |
net: phy: Add helper routines to set and clear bits
Add phy_set/clear_bit helper routines so that ported drivers from the
kernel can use these functions.
Acked-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Diffstat (limited to 'include/phy.h')
-rw-r--r-- | include/phy.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/phy.h b/include/phy.h index 34c2af719b..fedd146091 100644 --- a/include/phy.h +++ b/include/phy.h @@ -296,6 +296,60 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad, return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val); } +/** + * phy_set_bits_mmd - Convenience function for setting bits in a register + * on MMD + * @phydev: the phy_device struct + * @devad: the MMD containing register to modify + * @regnum: register number to modify + * @val: bits to set + * @return: 0 for success or negative errno for failure + */ +static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad, + u32 regnum, u16 val) +{ + int value, ret; + + value = phy_read_mmd(phydev, devad, regnum); + if (value < 0) + return value; + + value |= val; + + ret = phy_write_mmd(phydev, devad, regnum, value); + if (ret < 0) + return ret; + + return 0; +} + +/** + * phy_clear_bits_mmd - Convenience function for clearing bits in a register + * on MMD + * @phydev: the phy_device struct + * @devad: the MMD containing register to modify + * @regnum: register number to modify + * @val: bits to clear + * @return: 0 for success or negative errno for failure + */ +static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad, + u32 regnum, u16 val) +{ + int value, ret; + + value = phy_read_mmd(phydev, devad, regnum); + if (value < 0) + return value; + + value &= ~val; + + ret = phy_write_mmd(phydev, devad, regnum, value); + if (ret < 0) + return ret; + + return 0; +} + #ifdef CONFIG_PHYLIB_10G extern struct phy_driver gen10g_driver; |