Read phy address from device tree and use it to find the phy device
if not found then search in the range of 0 to 31.

Signed-off-by: Padmarao Begari <padmarao.beg...@microchip.com>
---
 drivers/net/macb.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 9ccbb7a166..81b1f1ba26 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -531,6 +531,12 @@ static int macb_phy_find(struct macb_device *macb, const 
char *name)
        int i;
        u16 phy_id;
 
+       phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1);
+       if (phy_id != 0xffff) {
+               printf("%s: PHY present at %d\n", name, macb->phy_addr);
+               return 0;
+       }
+
        /* Search for PHY... */
        for (i = 0; i < 32; i++) {
                macb->phy_addr = i;
@@ -1315,11 +1321,12 @@ static int macb_eth_probe(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_platdata(dev);
        struct macb_device *macb = dev_get_priv(dev);
+       struct ofnode_phandle_args phandle_args;
        const char *phy_mode;
        int ret;
 
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
+       phy_mode = dev_read_prop(dev, "phy-mode", NULL);
+
        if (phy_mode)
                macb->phy_interface = phy_get_interface_by_name(phy_mode);
        if (macb->phy_interface == -1) {
@@ -1327,6 +1334,12 @@ static int macb_eth_probe(struct udevice *dev)
                return -EINVAL;
        }
 
+       /* Read phyaddr from DT */
+       if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
+                                       &phandle_args))
+               macb->phy_addr = ofnode_read_u32_default(phandle_args.node,
+                                                        "reg", -1);
+
        macb->regs = (void *)pdata->iobase;
 
        macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678);
-- 
2.17.1

Reply via email to