Revert "ar71xx: ag71xx: Add connect message: fixed phy"
[openwrt/staging/wigyori.git] / target / linux / ar71xx / files / drivers / net / ethernet / atheros / ag71xx / ag71xx_phy.c
index ce9edc1f743ea97f2de0f1db289a597844baf5bb..daa373be693291ca5302470cfde4129a59d9e72f 100644 (file)
@@ -76,10 +76,24 @@ void ag71xx_phy_stop(struct ag71xx *ag)
 
 static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
 {
-       struct net_device *dev = ag->dev;
+       struct platform_device *pdev = ag->pdev;
+       struct device *dev = NULL;
        struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
        int ret = 0;
 
+       if (!pdev)
+               return -ENODEV;
+
+       dev = &pdev->dev;
+
+       if (!dev)
+               return -ENODEV;
+
+       if (!ag->phy_dev) {
+               pr_err("Missing PHY for %s", dev_name(dev));
+               return -ENODEV;
+       }
+
        /* use fixed settings */
        switch (pdata->speed) {
        case SPEED_10:
@@ -87,12 +101,12 @@ static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
        case SPEED_1000:
                break;
        default:
-               netdev_err(dev, "invalid speed specified\n");
+               dev_err(dev, "invalid speed specified\n");
                ret = -EINVAL;
                break;
        }
 
-       netdev_dbg(dev, "using fixed link parameters\n");
+       dev_dbg(dev, "using fixed link parameters\n");
 
        ag->duplex = pdata->duplex;
        ag->speed = pdata->speed;
@@ -102,7 +116,7 @@ static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
 
 static int ag71xx_phy_connect_multi(struct ag71xx *ag)
 {
-       struct net_device *dev = ag->dev;
+       struct device *dev = &ag->pdev->dev;
        struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
        struct phy_device *phydev = NULL;
        int phy_addr;
@@ -112,31 +126,52 @@ static int ag71xx_phy_connect_multi(struct ag71xx *ag)
                if (!(pdata->phy_mask & (1 << phy_addr)))
                        continue;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
                if (ag->mii_bus->phy_map[phy_addr] == NULL)
                        continue;
 
                DBG("%s: PHY found at %s, uid=%08x\n",
-                       dev->name,
+                       dev_name(dev),
                        dev_name(&ag->mii_bus->phy_map[phy_addr]->dev),
                        ag->mii_bus->phy_map[phy_addr]->phy_id);
 
                if (phydev == NULL)
                        phydev = ag->mii_bus->phy_map[phy_addr];
+#else
+               if (ag->mii_bus->mdio_map[phy_addr] == NULL)
+                       continue;
+
+               DBG("%s: PHY found at %s, uid=%08x\n",
+                       dev_name(dev),
+                       dev_name(&ag->mii_bus->mdio_map[phy_addr]->dev),
+                       ag->mii_bus->mdio_map[phy_addr]->phy_id);
+
+               if (phydev == NULL)
+                       phydev = mdiobus_get_phy(ag->mii_bus, phy_addr);
+#endif
        }
 
        if (!phydev) {
-               netdev_err(dev, "no PHY found with phy_mask=%08x\n",
+               dev_err(dev, "no PHY found with phy_mask=%08x\n",
                           pdata->phy_mask);
                return -ENODEV;
        }
 
-       ag->phy_dev = phy_connect(dev, dev_name(&phydev->dev),
-                                 &ag71xx_phy_link_adjust, 0,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
+       ag->phy_dev = phy_connect(ag->dev, dev_name(&phydev->dev),
+#else
+       ag->phy_dev = phy_connect(ag->dev, phydev_name(phydev),
+#endif
+                                 &ag71xx_phy_link_adjust,
                                  pdata->phy_if_mode);
 
        if (IS_ERR(ag->phy_dev)) {
-               netdev_err(dev, "could not connect to PHY at %s\n",
+               dev_err(dev, "could not connect to PHY at %s\n",
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
                           dev_name(&phydev->dev));
+#else
+                          phydev_name(phydev));
+#endif
                return PTR_ERR(ag->phy_dev);
        }
 
@@ -148,8 +183,13 @@ static int ag71xx_phy_connect_multi(struct ag71xx *ag)
 
        phydev->advertising = phydev->supported;
 
-       netdev_info(dev, "connected to PHY at %s [uid=%08x, driver=%s]\n",
-                   dev_name(&phydev->dev), phydev->phy_id, phydev->drv->name);
+       dev_info(dev, "connected to PHY at %s [uid=%08x, driver=%s]\n",
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
+                   dev_name(&phydev->dev),
+#else
+                   phydev_name(phydev),
+#endif
+                   phydev->phy_id, phydev->drv->name);
 
        ag->link = 0;
        ag->speed = 0;
@@ -193,7 +233,7 @@ static struct mii_bus *dev_to_mii_bus(struct device *dev)
        return NULL;
 }
 
-int __devinit ag71xx_phy_connect(struct ag71xx *ag)
+int ag71xx_phy_connect(struct ag71xx *ag)
 {
        struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
 
@@ -203,7 +243,7 @@ int __devinit ag71xx_phy_connect(struct ag71xx *ag)
 
        ag->mii_bus = dev_to_mii_bus(pdata->mii_bus_dev);
        if (ag->mii_bus == NULL) {
-               netdev_err(ag->dev, "unable to find MII bus on device '%s'\n",
+               dev_err(&ag->pdev->dev, "unable to find MII bus on device '%s'\n",
                           dev_name(pdata->mii_bus_dev));
                return -ENODEV;
        }