commit 5fe419ef2a61 ("net: Add eth phy generic driver for shared MDIO") added a UCLASS_ETH_PHY for Ethernet PHY devices to aid in connecting eth devices to mii bus drivers. However the binding was only allowed for a phy that was a child of the ethernet device which is fairly restrictive.
For a device such as an Ethernet switch the phy can be from a different bus and driver such as an I2C or SPI register controlled device. Remove the restiction of the phy being a child of the eth device. Additionally add some debugging, remove some unnecessary prints on successes, and remove FEC from a failure print. Cc: Ye Li <ye...@nxp.com> Cc: Peng Fan <peng....@nxp.com> Signed-off-by: Tim Harvey <thar...@gateworks.com> --- drivers/net/eth-phy-uclass.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c index b383f45..fb1b92b 100644 --- a/drivers/net/eth-phy-uclass.c +++ b/drivers/net/eth-phy-uclass.c @@ -6,6 +6,7 @@ #include <common.h> #include <dm.h> #include <net.h> +#include <phy.h> #include <dm/device-internal.h> #include <dm/uclass-internal.h> #include <dm/lists.h> @@ -51,13 +52,12 @@ int eth_phy_set_mdio_bus(struct udevice *eth_dev, struct mii_dev *mdio_bus) struct udevice *dev; struct eth_phy_device_priv *uc_priv; - for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev; - uclass_next_device(&dev)) { - if (dev->parent == eth_dev) { - uc_priv = (struct eth_phy_device_priv *)(dev->uclass_priv); - - if (!uc_priv->mdio_bus) - uc_priv->mdio_bus = mdio_bus; + debug("%s eth_dev:%s mdio_bus:%s\n", __func__, eth_dev->name, mdio_bus->name); + for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev; uclass_next_device(&dev)) { + uc_priv = (struct eth_phy_device_priv *)(dev->uclass_priv); + if (!uc_priv->mdio_bus) { + debug("%s setting to bus=%p:%s\n", __func__, mdio_bus, mdio_bus->name); + uc_priv->mdio_bus = mdio_bus; } } @@ -70,25 +70,20 @@ struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev) struct udevice *phy_dev; struct eth_phy_device_priv *uc_priv; + debug("%s eth_dev:%s\n", __func__, eth_dev->name); /* Will probe the parent of phy device, then phy device */ - ret = uclass_get_device_by_phandle(UCLASS_ETH_PHY, eth_dev, - "phy-handle", &phy_dev); + ret = uclass_get_device_by_phandle(UCLASS_ETH_PHY, eth_dev, "phy-handle", &phy_dev); if (!ret) { - if (eth_dev != phy_dev->parent) { - /* - * phy_dev is shared and controlled by - * other eth controller - */ - uc_priv = (struct eth_phy_device_priv *)(phy_dev->uclass_priv); - if (uc_priv->mdio_bus) - printf("Get shared mii bus on %s\n", eth_dev->name); - else - printf("Can't get shared mii bus on %s\n", eth_dev->name); - - return uc_priv->mdio_bus; - } + debug("%s phy_dev:%s\n", __func__, phy_dev->name); + uc_priv = (struct eth_phy_device_priv *)(phy_dev->uclass_priv); + if (uc_priv->mdio_bus) + debug("%s got mii bus for %s: %s\n", __func__, + eth_dev->name, uc_priv->mdio_bus->name); + else + printf("no mii bus for %s\n", phy_dev->name); + return uc_priv->mdio_bus; } else { - printf("FEC: can't find phy-handle\n"); + printf("can't find phy-handle\n"); } return NULL; -- 2.7.4