Skip to content

Commit 2b74e5b

Browse files
Russell Kingdavem330
authored andcommitted
net: phy: add phy_modify() accessor
Add phy_modify() convenience accessor to complement the mdiobus counterpart. Signed-off-by: Russell King <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 424ca4c commit 2b74e5b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/net/phy/phy-core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,29 @@ int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
349349
}
350350
EXPORT_SYMBOL_GPL(__phy_modify);
351351

352+
/**
353+
* phy_modify - Convenience function for modifying a given PHY register
354+
* @phydev: the phy_device struct
355+
* @regnum: register number to write
356+
* @mask: bit mask of bits to clear
357+
* @set: new value of bits set in mask to write to @regnum
358+
*
359+
* NOTE: MUST NOT be called from interrupt context,
360+
* because the bus read/write functions may wait for an interrupt
361+
* to conclude the operation.
362+
*/
363+
int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
364+
{
365+
int ret;
366+
367+
mutex_lock(&phydev->mdio.bus->mdio_lock);
368+
ret = __phy_modify(phydev, regnum, mask, set);
369+
mutex_unlock(&phydev->mdio.bus->mdio_lock);
370+
371+
return ret;
372+
}
373+
EXPORT_SYMBOL_GPL(phy_modify);
374+
352375
static int __phy_read_page(struct phy_device *phydev)
353376
{
354377
return phydev->drv->read_page(phydev);

include/linux/phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
762762
}
763763

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

766767
/**
767768
* phy_interrupt_is_valid - Convenience function for testing a given PHY irq

0 commit comments

Comments
 (0)