From patchwork Mon Apr 20 18:53:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 238123 List-Id: U-Boot discussion From: dmurphy at ti.com (Dan Murphy) Date: Mon, 20 Apr 2020 13:53:09 -0500 Subject: [RFC PATCH 2/3] net: phy: Add helper routines to set and clear bits In-Reply-To: <20200420185310.6630-1-dmurphy@ti.com> References: <20200420185310.6630-1-dmurphy@ti.com> Message-ID: <20200420185310.6630-2-dmurphy@ti.com> Add phy_set/clear_bit helper routines so that ported drivers from the kernel can use these functions. Signed-off-by: Dan Murphy --- include/phy.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/phy.h b/include/phy.h index b5de14cbfc29..050c989fa537 100644 --- a/include/phy.h +++ b/include/phy.h @@ -257,6 +257,44 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad, return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val); } +static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad, + u32 regnum, u16 val) +{ + int value; + int 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; +} + +static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad, + u32 regnum, u16 val) +{ + int value; + int 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;