Merge tag 'xilinx-for-v2020.01' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / drivers / net / phy / phy.c
index c1c1af9..f2d17aa 100644 (file)
@@ -458,6 +458,11 @@ static struct phy_driver genphy_driver = {
        .shutdown       = genphy_shutdown,
 };
 
+int genphy_init(void)
+{
+       return phy_register(&genphy_driver);
+}
+
 static LIST_HEAD(phy_drivers);
 
 int phy_init(void)
@@ -540,6 +545,11 @@ int phy_init(void)
 #ifdef CONFIG_PHY_FIXED
        phy_fixed_init();
 #endif
+#ifdef CONFIG_PHY_XILINX_GMII2RGMII
+       phy_xilinx_gmii2rgmii_init();
+#endif
+       genphy_init();
+
        return 0;
 }
 
@@ -727,12 +737,23 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
        while (phy_mask) {
                int addr = ffs(phy_mask) - 1;
                int r = get_phy_id(bus, addr, devad, &phy_id);
+
+               /*
+                * If the PHY ID is flat 0 we ignore it.  There are C45 PHYs
+                * that return all 0s for C22 reads (like Aquantia AQR112) and
+                * there are C22 PHYs that return all 0s for C45 reads (like
+                * Atheros AR8035).
+                */
+               if (r == 0 && phy_id == 0)
+                       goto next;
+
                /* If the PHY ID is mostly f's, we didn't find anything */
                if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) {
                        is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true;
                        return phy_device_create(bus, addr, phy_id, is_c45,
                                                 interface);
                }
+next:
                phy_mask &= ~(1 << addr);
        }
        return NULL;
@@ -900,6 +921,41 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
        debug("%s connected to %s\n", dev->name, phydev->drv->name);
 }
 
+#ifdef CONFIG_PHY_XILINX_GMII2RGMII
+#ifdef CONFIG_DM_ETH
+static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
+                                                struct udevice *dev,
+                                                phy_interface_t interface)
+#else
+static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
+                                                struct eth_device *dev,
+                                                phy_interface_t interface)
+#endif
+{
+       struct phy_device *phydev = NULL;
+       int sn = dev_of_offset(dev);
+       int off;
+
+       while (sn > 0) {
+               off = fdt_node_offset_by_compatible(gd->fdt_blob, sn,
+                                                   "xlnx,gmii-to-rgmii-1.0");
+               if (off > 0) {
+                       phydev = phy_device_create(bus, off,
+                                                  PHY_GMII2RGMII_ID, false,
+                                                  interface);
+                       break;
+               }
+               if (off == -FDT_ERR_NOTFOUND)
+                       sn = fdt_first_subnode(gd->fdt_blob, sn);
+               else
+                       printf("%s: Error finding compat string:%d\n",
+                              __func__, off);
+       }
+
+       return phydev;
+}
+#endif
+
 #ifdef CONFIG_PHY_FIXED
 #ifdef CONFIG_DM_ETH
 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
@@ -946,6 +1002,10 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,
 #ifdef CONFIG_PHY_FIXED
        phydev = phy_connect_fixed(bus, dev, interface);
 #endif
+#ifdef CONFIG_PHY_XILINX_GMII2RGMII
+       if (!phydev)
+               phydev = phy_connect_gmii2rgmii(bus, dev, interface);
+#endif
 
        if (!phydev)
                phydev = phy_find_by_mask(bus, mask, interface);