Skip to content

Commit

Permalink
net: phy: add helpers phy_(un)lock_mdio_bus
Browse files Browse the repository at this point in the history
Add helpers to make locking/unlocking the MDIO bus easier.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Heiner Kallweit authored and David S. Miller committed Nov 25, 2019
1 parent 4eb4719 commit bec170e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
28 changes: 14 additions & 14 deletions drivers/net/phy/phy-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
{
int ret;

mutex_lock(&phydev->mdio.bus->mdio_lock);
phy_lock_mdio_bus(phydev);
ret = __phy_read_mmd(phydev, devad, regnum);
mutex_unlock(&phydev->mdio.bus->mdio_lock);
phy_unlock_mdio_bus(phydev);

return ret;
}
Expand Down Expand Up @@ -480,9 +480,9 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
{
int ret;

mutex_lock(&phydev->mdio.bus->mdio_lock);
phy_lock_mdio_bus(phydev);
ret = __phy_write_mmd(phydev, devad, regnum, val);
mutex_unlock(&phydev->mdio.bus->mdio_lock);
phy_unlock_mdio_bus(phydev);

return ret;
}
Expand Down Expand Up @@ -536,9 +536,9 @@ int phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
{
int ret;

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

return ret;
}
Expand Down Expand Up @@ -580,9 +580,9 @@ int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
{
int ret;

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

return ret;
}
Expand Down Expand Up @@ -639,9 +639,9 @@ int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
{
int ret;

mutex_lock(&phydev->mdio.bus->mdio_lock);
phy_lock_mdio_bus(phydev);
ret = __phy_modify_mmd_changed(phydev, devad, regnum, mask, set);
mutex_unlock(&phydev->mdio.bus->mdio_lock);
phy_unlock_mdio_bus(phydev);

return ret;
}
Expand Down Expand Up @@ -687,9 +687,9 @@ int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
{
int ret;

mutex_lock(&phydev->mdio.bus->mdio_lock);
phy_lock_mdio_bus(phydev);
ret = __phy_modify_mmd(phydev, devad, regnum, mask, set);
mutex_unlock(&phydev->mdio.bus->mdio_lock);
phy_unlock_mdio_bus(phydev);

return ret;
}
Expand Down Expand Up @@ -721,7 +721,7 @@ static int __phy_write_page(struct phy_device *phydev, int page)
*/
int phy_save_page(struct phy_device *phydev)
{
mutex_lock(&phydev->mdio.bus->mdio_lock);
phy_lock_mdio_bus(phydev);
return __phy_read_page(phydev);
}
EXPORT_SYMBOL_GPL(phy_save_page);
Expand Down Expand Up @@ -788,7 +788,7 @@ int phy_restore_page(struct phy_device *phydev, int oldpage, int ret)
ret = oldpage;
}

mutex_unlock(&phydev->mdio.bus->mdio_lock);
phy_unlock_mdio_bus(phydev);

return ret;
}
Expand Down
10 changes: 10 additions & 0 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,16 @@ static inline const char *phydev_name(const struct phy_device *phydev)
return dev_name(&phydev->mdio.dev);
}

static inline void phy_lock_mdio_bus(struct phy_device *phydev)
{
mutex_lock(&phydev->mdio.bus->mdio_lock);
}

static inline void phy_unlock_mdio_bus(struct phy_device *phydev)
{
mutex_unlock(&phydev->mdio.bus->mdio_lock);
}

void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
__printf(2, 3);
void phy_attached_info(struct phy_device *phydev);
Expand Down

0 comments on commit bec170e

Please sign in to comment.