[PATCH u-boot-marvell 06/19] net: mdio-uclass: add dm_phy_find_by_ofnode() helper

Stefan Roese sr at denx.de
Mon May 2 09:00:40 CEST 2022


On 27.04.22 12:41, Marek Behún wrote:
> From: Marek Behún <marek.behun at nic.cz>
> 
> Add helper to resolve PHY node from it's ofnode via DM MDIO subsystem.
> 
> Signed-off-by: Marek Behún <marek.behun at nic.cz>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan


> ---
>   include/miiphy.h  |  9 +++++++++
>   net/mdio-uclass.c | 22 ++++++++++++++++++++++
>   2 files changed, 31 insertions(+)
> 
> diff --git a/include/miiphy.h b/include/miiphy.h
> index 110921f20d..c66a1845b5 100644
> --- a/include/miiphy.h
> +++ b/include/miiphy.h
> @@ -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
>    *
> diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
> index 7593618d9a..4401492ca0 100644
> --- a/net/mdio-uclass.c
> +++ b/net/mdio-uclass.c
> @@ -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)

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list