Skip to content

Commit

Permalink
net: mdio-uclass: add dm_phy_find_by_ofnode() helper
Browse files Browse the repository at this point in the history
Add helper to resolve PHY node from it's ofnode via DM MDIO subsystem.

Signed-off-by: Marek Behún <[email protected]>
Reviewed-by: Ramon Fried <[email protected]>
Reviewed-by: Stefan Roese <[email protected]>
  • Loading branch information
elkablo authored and stroese committed May 4, 2022
1 parent a2b2542 commit 00b1bad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/miiphy.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 va
*/
int dm_mdio_reset(struct udevice *mdio_dev);

/**
* dm_phy_find_by_ofnode - Find PHY device by ofnode
*
* @phynode: PHY's ofnode
*
* Return: pointer to phy_device, or NULL on error
*/
struct phy_device *dm_phy_find_by_ofnode(ofnode phynode);

/**
* dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
*
Expand Down
22 changes: 22 additions & 0 deletions net/mdio-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ static int dm_mdio_pre_remove(struct udevice *dev)
return 0;
}

struct phy_device *dm_phy_find_by_ofnode(ofnode phynode)
{
struct mdio_perdev_priv *pdata;
struct udevice *mdiodev;
u32 phy_addr;

if (ofnode_read_u32(phynode, "reg", &phy_addr))
return NULL;

if (uclass_get_device_by_ofnode(UCLASS_MDIO,
ofnode_get_parent(phynode),
&mdiodev))
return NULL;

if (device_probe(mdiodev))
return NULL;

pdata = dev_get_uclass_priv(mdiodev);

return phy_find_by_mask(pdata->mii_bus, BIT(phy_addr));
}

struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr,
struct udevice *ethdev,
phy_interface_t interface)
Expand Down

0 comments on commit 00b1bad

Please sign in to comment.