Re: [net-next PATCH v2 1/3] net: phy: introduce find_phy_device()
From: Andy Shevchenko
Date: Wed Jul 01 2020 - 06:23:48 EST
On Wed, Jul 1, 2020 at 9:13 AM Calvin Johnson
<calvin.johnson@xxxxxxxxxxx> wrote:
>
> The PHYs on a mdiobus are probed and registered using mdiobus_register().
> Later, for connecting these PHYs to MAC, the PHYs registered on the
> mdiobus have to be referenced.
>
> For each MAC node, a property "mdio-handle" is used to reference the
> MDIO bus on which the PHYs are registered. On getting hold of the MDIO
> bus, use find_phy_device() to get the PHY connected to the MAC.
...
> + struct platform_device *pdev;
This...
> + fwnode_mdio = fwnode_find_reference(fwnode, "mdio-handle", 0);
> + dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode_mdio);
> + if (IS_ERR_OR_NULL(dev))
IS_ERR()?!
> + return NULL;
> + pdev = to_platform_device(dev);
> + mdio = platform_get_drvdata(pdev);
...and this can be simple:
mdio = dev_get_drvdata(dev);
> + err = fwnode_property_read_u32(fwnode, "phy-channel", &addr);
> + if (err < 0 || addr < 0 || addr >= PHY_MAX_ADDR)
> + return NULL;
--
With Best Regards,
Andy Shevchenko