Merge branch 'master' of git://git.denx.de/u-boot-fsl-qoriq
[oweals/u-boot.git] / drivers / net / phy / phy.c
index 9d88afe8fc8dab8f57bb65e545dc3bc66cddcfed..51b5746a5a49739c2b71e0a87e115b644f98b6e7 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <config.h>
 #include <common.h>
+#include <console.h>
 #include <dm.h>
 #include <malloc.h>
 #include <net.h>
@@ -21,6 +22,8 @@
 #include <linux/err.h>
 #include <linux/compiler.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* Generic PHY support and helper functions */
 
 /**
@@ -482,6 +485,9 @@ int phy_init(void)
 #ifdef CONFIG_PHY_TERANETICS
        phy_teranetics_init();
 #endif
+#ifdef CONFIG_PHY_TI
+       phy_ti_init();
+#endif
 #ifdef CONFIG_PHY_VITESSE
        phy_vitesse_init();
 #endif
@@ -494,6 +500,20 @@ int phy_register(struct phy_driver *drv)
        INIT_LIST_HEAD(&drv->list);
        list_add_tail(&drv->list, &phy_drivers);
 
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+       if (drv->probe)
+               drv->probe += gd->reloc_off;
+       if (drv->config)
+               drv->config += gd->reloc_off;
+       if (drv->startup)
+               drv->startup += gd->reloc_off;
+       if (drv->shutdown)
+               drv->shutdown += gd->reloc_off;
+       if (drv->readext)
+               drv->readext += gd->reloc_off;
+       if (drv->writeext)
+               drv->writeext += gd->reloc_off;
+#endif
        return 0;
 }
 
@@ -538,7 +558,7 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev,
 }
 
 static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
-                                           int phy_id,
+                                           u32 phy_id,
                                            phy_interface_t interface)
 {
        struct phy_device *dev;
@@ -555,7 +575,7 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
        memset(dev, 0, sizeof(*dev));
 
        dev->duplex = -1;
-       dev->link = 1;
+       dev->link = 0;
        dev->interface = interface;
 
        dev->autoneg = AUTONEG_ENABLE;
@@ -582,7 +602,7 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
  * Description: Reads the ID registers of the PHY at @addr on the
  *   @bus, stores it in @phy_id and returns zero on success.
  */
-static int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
+int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
 {
        int phy_reg;
 
@@ -655,8 +675,16 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
                if (phydev)
                        return phydev;
        }
-       printf("Phy %d not found\n", ffs(phy_mask) - 1);
-       return phy_device_create(bus, ffs(phy_mask) - 1, 0xffffffff, interface);
+
+       debug("\n%s PHY: ", bus->name);
+       while (phy_mask) {
+               int addr = ffs(phy_mask) - 1;
+               debug("%d ", addr);
+               phy_mask &= ~(1 << addr);
+       }
+       debug("not found\n");
+
+       return NULL;
 }
 
 /**
@@ -747,11 +775,13 @@ struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
                phy_interface_t interface)
 {
        /* Reset the bus */
-       if (bus->reset)
+       if (bus->reset) {
                bus->reset(bus);
 
-       /* Wait 15ms to make sure the PHY has come out of hard reset */
-       udelay(15000);
+               /* Wait 15ms to make sure the PHY has come out of hard reset */
+               udelay(15000);
+       }
+
        return get_phy_device_by_mask(bus, phy_mask, interface);
 }
 
@@ -763,7 +793,7 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
 {
        /* Soft Reset the PHY */
        phy_reset(phydev);
-       if (phydev->dev) {
+       if (phydev->dev && phydev->dev != dev) {
                printf("%s:%d is connected to %s.  Reconnecting to %s\n",
                                phydev->bus->name, phydev->addr,
                                phydev->dev->name, dev->name);