net: sun8i_emac: Retrieve GMAC clock via 'syscon' phandle
[oweals/u-boot.git] / drivers / net / macb.c
index fe370bf728975321d7cdb09a943d9290977fb044..72614164e9c7c36c283ece131a334468d78cc9f4 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2005-2006 Atmel Corporation
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 #include <common.h>
 #include <clk.h>
@@ -144,7 +143,7 @@ struct macb_device {
 
 static int macb_is_gem(struct macb_device *macb)
 {
-       return MACB_BFEXT(IDNUM, macb_readl(macb, MID)) == 0x2;
+       return MACB_BFEXT(IDNUM, macb_readl(macb, MID)) >= 0x2;
 }
 
 #ifndef cpu_is_sama5d2
@@ -551,8 +550,14 @@ static int macb_phy_init(struct macb_device *macb, const char *name)
 
                for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) {
                        status = macb_mdio_read(macb, MII_BMSR);
-                       if (status & BMSR_LSTATUS)
+                       if (status & BMSR_LSTATUS) {
+                               /*
+                                * Delay a bit after the link is established,
+                                * so that the next xfer does not fail
+                                */
+                               mdelay(10);
                                break;
+                       }
                        udelay(100);
                }
        }
@@ -1062,14 +1067,13 @@ static int macb_enable_clk(struct udevice *dev)
                return -EINVAL;
 
        /*
-        * Zynq clock driver didn't support for enable or disable
-        * clock. Hence, clk_enable() didn't apply for Zynq
+        * If clock driver didn't support enable or disable then
+        * we get -ENOSYS from clk_enable(). To handle this, we
+        * don't fail for ret == -ENOSYS.
         */
-#ifndef CONFIG_MACB_ZYNQ
        ret = clk_enable(&clk);
-       if (ret)
+       if (ret && ret != -ENOSYS)
                return ret;
-#endif
 
        clk_rate = clk_get_rate(&clk);
        if (!clk_rate)
@@ -1152,7 +1156,9 @@ static int macb_eth_ofdata_to_platdata(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_platdata(dev);
 
-       pdata->iobase = devfdt_get_addr(dev);
+       pdata->iobase = (phys_addr_t)dev_remap_addr(dev);
+       if (!pdata->iobase)
+               return -EINVAL;
 
        return macb_late_eth_ofdata_to_platdata(dev);
 }