mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-30 16:13:27 +08:00
net: phy: Add generic helpers to access MMD PHY registers
Two new helper functions (phy_read_mmd() and phy_write_mmd()) are added to allow access to the MMD PHY registers. The MMD PHY registers can be accessed by several means: 1. Using two new MMD access function hooks in the PHY driver. These functions can be implemented when the PHY driver does not support the standard IEEE Compatible clause 45 access mechanism described in clause 22 or if the PHY uses its own non-standard access mechanism. 2. Direct access for C45 PHYs and C22 PHYs when accessing the reachable DEVADs. 3. The standard clause 45 access extensions to the MMD registers through the indirection registers (clause 22) in all the other cases. Signed-off-by: Carlo Caione <ccaione@baylibre.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
parent
8d7f06bbbe
commit
4f6746dc7f
@ -549,6 +549,10 @@ int phy_register(struct phy_driver *drv)
|
||||
drv->readext += gd->reloc_off;
|
||||
if (drv->writeext)
|
||||
drv->writeext += gd->reloc_off;
|
||||
if (drv->read_mmd)
|
||||
drv->read_mmd += gd->reloc_off;
|
||||
if (drv->write_mmd)
|
||||
drv->write_mmd += gd->reloc_off;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -101,6 +101,14 @@ struct phy_driver {
|
||||
int (*readext)(struct phy_device *phydev, int addr, int devad, int reg);
|
||||
int (*writeext)(struct phy_device *phydev, int addr, int devad, int reg,
|
||||
u16 val);
|
||||
|
||||
/* Phy specific driver override for reading a MMD register */
|
||||
int (*read_mmd)(struct phy_device *phydev, int devad, int reg);
|
||||
|
||||
/* Phy specific driver override for writing a MMD register */
|
||||
int (*write_mmd)(struct phy_device *phydev, int devad, int reg,
|
||||
u16 val);
|
||||
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
@ -165,6 +173,68 @@ static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
|
||||
return bus->write(bus, phydev->addr, devad, regnum, val);
|
||||
}
|
||||
|
||||
static inline void phy_mmd_start_indirect(struct phy_device *phydev, int devad,
|
||||
int regnum)
|
||||
{
|
||||
/* Write the desired MMD Devad */
|
||||
phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, devad);
|
||||
|
||||
/* Write the desired MMD register address */
|
||||
phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, regnum);
|
||||
|
||||
/* Select the Function : DATA with no post increment */
|
||||
phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL,
|
||||
(devad | MII_MMD_CTRL_NOINCR));
|
||||
}
|
||||
|
||||
static inline int phy_read_mmd(struct phy_device *phydev, int devad,
|
||||
int regnum)
|
||||
{
|
||||
struct phy_driver *drv = phydev->drv;
|
||||
|
||||
if (regnum > (u16)~0 || devad > 32)
|
||||
return -EINVAL;
|
||||
|
||||
/* driver-specific access */
|
||||
if (drv->read_mmd)
|
||||
return drv->read_mmd(phydev, devad, regnum);
|
||||
|
||||
/* direct C45 / C22 access */
|
||||
if ((drv->features & PHY_10G_FEATURES) == PHY_10G_FEATURES ||
|
||||
devad == MDIO_DEVAD_NONE || !devad)
|
||||
return phy_read(phydev, devad, regnum);
|
||||
|
||||
/* indirect C22 access */
|
||||
phy_mmd_start_indirect(phydev, devad, regnum);
|
||||
|
||||
/* Read the content of the MMD's selected register */
|
||||
return phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA);
|
||||
}
|
||||
|
||||
static inline int phy_write_mmd(struct phy_device *phydev, int devad,
|
||||
int regnum, u16 val)
|
||||
{
|
||||
struct phy_driver *drv = phydev->drv;
|
||||
|
||||
if (regnum > (u16)~0 || devad > 32)
|
||||
return -EINVAL;
|
||||
|
||||
/* driver-specific access */
|
||||
if (drv->write_mmd)
|
||||
return drv->write_mmd(phydev, devad, regnum, val);
|
||||
|
||||
/* direct C45 / C22 access */
|
||||
if ((drv->features & PHY_10G_FEATURES) == PHY_10G_FEATURES ||
|
||||
devad == MDIO_DEVAD_NONE || !devad)
|
||||
return phy_write(phydev, devad, regnum, val);
|
||||
|
||||
/* indirect C22 access */
|
||||
phy_mmd_start_indirect(phydev, devad, regnum);
|
||||
|
||||
/* Write the data into MMD's selected register */
|
||||
return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PHYLIB_10G
|
||||
extern struct phy_driver gen10g_driver;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user