Skip to content

Commit 788f993

Browse files
Russell Kingdavem330
authored andcommitted
net: phy: add unlocked accessors
Add unlocked versions of the bus accessors, which allows access to the bus with all the tracing. These accessors validate that the bus mutex is held, which is a basic requirement for all mii bus accesses. Also added is a read-modify-write unlocked accessor with the same locking requirements. Signed-off-by: Russell King <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1b2dea2 commit 788f993

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

drivers/net/phy/phy-core.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,28 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
323323
return ret;
324324
}
325325
EXPORT_SYMBOL(phy_write_mmd);
326+
327+
/**
328+
* __phy_modify() - Convenience function for modifying a PHY register
329+
* @phydev: a pointer to a &struct phy_device
330+
* @regnum: register number
331+
* @mask: bit mask of bits to clear
332+
* @set: bit mask of bits to set
333+
*
334+
* Unlocked helper function which allows a PHY register to be modified as
335+
* new register value = (old register value & mask) | set
336+
*/
337+
int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
338+
{
339+
int ret, res;
340+
341+
ret = __phy_read(phydev, regnum);
342+
if (ret >= 0) {
343+
res = __phy_write(phydev, regnum, (ret & ~mask) | set);
344+
if (res < 0)
345+
ret = res;
346+
}
347+
348+
return ret;
349+
}
350+
EXPORT_SYMBOL_GPL(__phy_modify);

include/linux/phy.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,18 @@ static inline int phy_read(struct phy_device *phydev, u32 regnum)
717717
return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
718718
}
719719

720+
/**
721+
* __phy_read - convenience function for reading a given PHY register
722+
* @phydev: the phy_device struct
723+
* @regnum: register number to read
724+
*
725+
* The caller must have taken the MDIO bus lock.
726+
*/
727+
static inline int __phy_read(struct phy_device *phydev, u32 regnum)
728+
{
729+
return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
730+
}
731+
720732
/**
721733
* phy_write - Convenience function for writing a given PHY register
722734
* @phydev: the phy_device struct
@@ -732,6 +744,22 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
732744
return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
733745
}
734746

747+
/**
748+
* __phy_write - Convenience function for writing a given PHY register
749+
* @phydev: the phy_device struct
750+
* @regnum: register number to write
751+
* @val: value to write to @regnum
752+
*
753+
* The caller must have taken the MDIO bus lock.
754+
*/
755+
static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
756+
{
757+
return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum,
758+
val);
759+
}
760+
761+
int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
762+
735763
/**
736764
* phy_interrupt_is_valid - Convenience function for testing a given PHY irq
737765
* @phydev: the phy_device struct

0 commit comments

Comments
 (0)