]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/net/fec_mxc.c
net: fec_mxc: exempt already found PHYs from being probed again
[karo-tx-uboot.git] / drivers / net / fec_mxc.c
index ee6822af323df3dd2970cc2341ce9f23d37e33e7..9c27889c7c36c9320158d21cde5505cd34a7737a 100644 (file)
@@ -110,7 +110,7 @@ static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyAddr,
                        if (readl(&eth->ievent) & FEC_IEVENT_MII)
                                break;
                        printf("Read MDIO failed...\n");
-                       return -1;
+                       return -ETIMEDOUT;
                }
        }
 
@@ -165,7 +165,7 @@ static int fec_mdio_write(struct ethernet_regs *eth, uint8_t phyAddr,
                        if (readl(&eth->ievent) & FEC_IEVENT_MII)
                                break;
                        printf("Write MDIO failed...\n");
-                       return -1;
+                       return -ETIMEDOUT;
                }
        }
 
@@ -227,7 +227,7 @@ static int miiphy_restart_aneg(struct eth_device *dev)
 
 static int miiphy_wait_aneg(struct eth_device *dev)
 {
-       uint32_t start;
+       ulong start;
        int status;
        struct fec_priv *fec = (struct fec_priv *)dev->priv;
        struct ethernet_regs *eth = fec->bus->priv;
@@ -239,14 +239,14 @@ static int miiphy_wait_aneg(struct eth_device *dev)
        do {
                if (get_timer(start) > (CONFIG_SYS_HZ * 5)) {
                        printf("%s: Autonegotiation timeout\n", dev->name);
-                       return -1;
+                       return -ETIMEDOUT;
                }
 
                status = fec_mdio_read(eth, fec->phy_id, MII_BMSR);
                if (status < 0) {
                        printf("%s: Autonegotiation failed. status: %d\n",
                                        dev->name, status);
-                       return -1;
+                       return status;
                }
        } while (!(status & BMSR_LSTATUS));
 
@@ -284,7 +284,7 @@ static inline void fec_tx_task_disable(struct fec_priv *fec)
 static void fec_rbd_init(struct fec_priv *fec, int count, int dsize)
 {
        uint32_t size;
-       uint8_t *data;
+       void *data;
        int i;
 
        /*
@@ -293,9 +293,10 @@ static void fec_rbd_init(struct fec_priv *fec, int count, int dsize)
         */
        size = roundup(dsize, ARCH_DMA_MINALIGN);
        for (i = 0; i < count; i++) {
-               data = (uint8_t *)fec->rbd_base[i].data_pointer;
+               data = (void *)fec->rbd_base[i].data_pointer;
                memset(data, 0, dsize);
-               flush_dcache_range((uint32_t)data, (uint32_t)data + size);
+               flush_dcache_range((unsigned long)data,
+                               (unsigned long)data + size);
 
                fec->rbd_base[i].status = FEC_RBD_EMPTY;
                fec->rbd_base[i].data_length = 0;
@@ -305,8 +306,8 @@ static void fec_rbd_init(struct fec_priv *fec, int count, int dsize)
        fec->rbd_base[i - 1].status = FEC_RBD_WRAP | FEC_RBD_EMPTY;
        fec->rbd_index = 0;
 
-       flush_dcache_range((unsigned)fec->rbd_base,
-                          (unsigned)fec->rbd_base + size);
+       flush_dcache_range((unsigned long)fec->rbd_base,
+                          (unsigned long)fec->rbd_base + size);
 }
 
 /**
@@ -323,7 +324,7 @@ static void fec_rbd_init(struct fec_priv *fec, int count, int dsize)
  */
 static void fec_tbd_init(struct fec_priv *fec)
 {
-       unsigned addr = (unsigned)fec->tbd_base;
+       unsigned long addr = (unsigned long)fec->tbd_base;
        unsigned size = roundup(2 * sizeof(struct fec_bd),
                                ARCH_DMA_MINALIGN);
 
@@ -358,7 +359,7 @@ static int fec_get_hwaddr(struct eth_device *dev, int dev_id,
 static int fec_set_hwaddr(struct eth_device *dev)
 {
        uchar *mac = dev->enetaddr;
-       struct fec_priv *fec = (struct fec_priv *)dev->priv;
+       struct fec_priv *fec = dev->priv;
 
        writel(0, &fec->eth->iaddr1);
        writel(0, &fec->eth->iaddr2);
@@ -583,7 +584,7 @@ static int fec_init(struct eth_device *dev, bd_t* bd)
  */
 static void fec_halt(struct eth_device *dev)
 {
-       struct fec_priv *fec = (struct fec_priv *)dev->priv;
+       struct fec_priv *fec = dev->priv;
        int counter = 1000;
 
        /*
@@ -642,7 +643,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
         */
        if ((length > 1500) || (length <= 0)) {
                printf("Payload (%d) too large\n", length);
-               return -1;
+               return -EINVAL;
        }
 
        /*
@@ -651,7 +652,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
         * engine. We also flush the packet to RAM here to avoid cache trouble.
         */
 #ifdef CONFIG_FEC_MXC_SWAP_PACKET
-       swap_packet((uint32_t *)packet, length);
+       swap_packet(packet, length);
 #endif
 
        addr = (uint32_t)packet;
@@ -723,7 +724,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
        }
 
        if (!timeout) {
-               ret = -EINVAL;
+               ret = -ETIMEDOUT;
                goto out;
        }
 
@@ -751,7 +752,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
        }
 
        if (!timeout)
-               ret = -EINVAL;
+               ret = -ETIMEDOUT;
 
 out:
        debug("fec_send: status 0x%x index %d ret %i\n",
@@ -773,7 +774,7 @@ out:
  */
 static int fec_recv(struct eth_device *dev)
 {
-       struct fec_priv *fec = (struct fec_priv *)dev->priv;
+       struct fec_priv *fec = dev->priv;
        struct fec_bd *rbd = &fec->rbd_base[fec->rbd_index];
        unsigned long ievent;
        int frame_length, len = 0;
@@ -899,7 +900,7 @@ static int fec_alloc_descs(struct fec_priv *fec)
 {
        unsigned int size;
        int i;
-       uint8_t *data;
+       void *data;
 
        /* Allocate TX descriptors. */
        size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN);
@@ -932,7 +933,8 @@ static int fec_alloc_descs(struct fec_priv *fec)
                fec->rbd_base[i].status = FEC_RBD_EMPTY;
                fec->rbd_base[i].data_length = 0;
                /* Flush the buffer to memory. */
-               flush_dcache_range((uint32_t)data, (uint32_t)data + size);
+               flush_dcache_range((unsigned long)data,
+                               (unsigned long)data + size);
        }
 
        /* Mark the last RBD to close the ring. */
@@ -1089,12 +1091,14 @@ int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr)
 #endif
        int ret;
 
-#ifdef CONFIG_SOC_MX28
+#if defined(CONFIG_SOC_MX28)
        /*
         * The i.MX28 has two ethernet interfaces, but they are not equal.
         * Only the first one can access the MDIO bus.
         */
        base_mii = MXS_ENET0_BASE;
+#elif defined(FEC_MDIO_BASE_ADDR)
+       base_mii = FEC_MDIO_BASE_ADDR;
 #else
        base_mii = addr;
 #endif
@@ -1103,12 +1107,14 @@ int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr)
        if (!bus)
                return -ENOMEM;
 #ifdef CONFIG_PHYLIB
-       phydev = phy_find_by_mask(bus, phy_id < 0 ? 0xff : (1 << phy_id),
+       static u8 phy_mask = 0xff;
+       phydev = phy_find_by_mask(bus, phy_id < 0 ? phy_mask : (1 << phy_id),
                                PHY_INTERFACE_MODE_RGMII);
        if (!phydev) {
                free(bus);
                return -ENOMEM;
        }
+       phy_mask &= ~(1 << phydev->addr);
        ret = fec_probe(bd, dev_id, addr, bus, phydev);
 #else
        ret = fec_probe(bd, dev_id, addr, bus, phy_id);
@@ -1133,7 +1139,7 @@ int fecmxc_initialize(bd_t *bd)
 #ifndef CONFIG_PHYLIB
 int fecmxc_register_mii_postcall(struct eth_device *dev, int (*cb)(int))
 {
-       struct fec_priv *fec = (struct fec_priv *)dev->priv;
+       struct fec_priv *fec = dev->priv;
        fec->mii_postcall = cb;
        return 0;
 }