Skip to content

Commit 028672b

Browse files
Ansueldavem330
authored andcommitted
net: phy: restructure __phy_write/read_mmd to helper and phydev user
Restructure phy_write_mmd and phy_read_mmd to implement generic helper for direct mdiobus access for mmd and use these helper for phydev user. This is needed in preparation of PHY package API that requires generic access to the mdiobus and are deatched from phydev struct but instead access them based on PHY package base_addr and offsets. Signed-off-by: Christian Marangi <[email protected]> Reviewed-by: Russell King (Oracle) <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9eea577 commit 028672b

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

drivers/net/phy/phy-core.c

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,28 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
540540
devad | MII_MMD_CTRL_NOINCR);
541541
}
542542

543+
static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45,
544+
int devad, u32 regnum)
545+
{
546+
if (is_c45)
547+
return __mdiobus_c45_read(bus, phy_addr, devad, regnum);
548+
549+
mmd_phy_indirect(bus, phy_addr, devad, regnum);
550+
/* Read the content of the MMD's selected register */
551+
return __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
552+
}
553+
554+
static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45,
555+
int devad, u32 regnum, u16 val)
556+
{
557+
if (is_c45)
558+
return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val);
559+
560+
mmd_phy_indirect(bus, phy_addr, devad, regnum);
561+
/* Write the data into MMD's selected register */
562+
return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
563+
}
564+
543565
/**
544566
* __phy_read_mmd - Convenience function for reading a register
545567
* from an MMD on a given PHY.
@@ -551,26 +573,14 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
551573
*/
552574
int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
553575
{
554-
int val;
555-
556576
if (regnum > (u16)~0 || devad > 32)
557577
return -EINVAL;
558578

559-
if (phydev->drv && phydev->drv->read_mmd) {
560-
val = phydev->drv->read_mmd(phydev, devad, regnum);
561-
} else if (phydev->is_c45) {
562-
val = __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr,
563-
devad, regnum);
564-
} else {
565-
struct mii_bus *bus = phydev->mdio.bus;
566-
int phy_addr = phydev->mdio.addr;
579+
if (phydev->drv && phydev->drv->read_mmd)
580+
return phydev->drv->read_mmd(phydev, devad, regnum);
567581

568-
mmd_phy_indirect(bus, phy_addr, devad, regnum);
569-
570-
/* Read the content of the MMD's selected register */
571-
val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
572-
}
573-
return val;
582+
return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr,
583+
phydev->is_c45, devad, regnum);
574584
}
575585
EXPORT_SYMBOL(__phy_read_mmd);
576586

@@ -607,28 +617,14 @@ EXPORT_SYMBOL(phy_read_mmd);
607617
*/
608618
int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
609619
{
610-
int ret;
611-
612620
if (regnum > (u16)~0 || devad > 32)
613621
return -EINVAL;
614622

615-
if (phydev->drv && phydev->drv->write_mmd) {
616-
ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
617-
} else if (phydev->is_c45) {
618-
ret = __mdiobus_c45_write(phydev->mdio.bus, phydev->mdio.addr,
619-
devad, regnum, val);
620-
} else {
621-
struct mii_bus *bus = phydev->mdio.bus;
622-
int phy_addr = phydev->mdio.addr;
623+
if (phydev->drv && phydev->drv->write_mmd)
624+
return phydev->drv->write_mmd(phydev, devad, regnum, val);
623625

624-
mmd_phy_indirect(bus, phy_addr, devad, regnum);
625-
626-
/* Write the data into MMD's selected register */
627-
__mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
628-
629-
ret = 0;
630-
}
631-
return ret;
626+
return mmd_phy_write(phydev->mdio.bus, phydev->mdio.addr,
627+
phydev->is_c45, devad, regnum, val);
632628
}
633629
EXPORT_SYMBOL(__phy_write_mmd);
634630

0 commit comments

Comments
 (0)