Skip to content

Commit

Permalink
net: phy: add phy_modify() accessor
Browse files Browse the repository at this point in the history
Add phy_modify() convenience accessor to complement the mdiobus
counterpart.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Russell King authored and David S. Miller committed Jan 3, 2018
1 parent 424ca4c commit 2b74e5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions drivers/net/phy/phy-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,29 @@ int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
}
EXPORT_SYMBOL_GPL(__phy_modify);

/**
* phy_modify - Convenience function for modifying a given PHY register
* @phydev: the phy_device struct
* @regnum: register number to write
* @mask: bit mask of bits to clear
* @set: new value of bits set in mask to write to @regnum
*
* NOTE: MUST NOT be called from interrupt context,
* because the bus read/write functions may wait for an interrupt
* to conclude the operation.
*/
int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
{
int ret;

mutex_lock(&phydev->mdio.bus->mdio_lock);
ret = __phy_modify(phydev, regnum, mask, set);
mutex_unlock(&phydev->mdio.bus->mdio_lock);

return ret;
}
EXPORT_SYMBOL_GPL(phy_modify);

static int __phy_read_page(struct phy_device *phydev)
{
return phydev->drv->read_page(phydev);
Expand Down
1 change: 1 addition & 0 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
}

int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);

/**
* phy_interrupt_is_valid - Convenience function for testing a given PHY irq
Expand Down

0 comments on commit 2b74e5b

Please sign in to comment.