]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/mcfmii.c
dwc2 USB controller hangs with lan78xx
[u-boot] / drivers / net / mcfmii.c
index 2b733c66e306b0d9d635bb7afe19e37c47eab2b1..961618b4109c62f26a116b21302832b30f03b25f 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2004-2008 Freescale Semiconductor, Inc.
  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 #include <common.h>
@@ -35,7 +18,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
+#if defined(CONFIG_CMD_NET)
 #undef MII_DEBUG
 #undef ET_DEBUG
 
@@ -171,42 +154,43 @@ int mii_discover_phy(struct eth_device *dev)
 
                for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
 
-                       phytype = mii_send(mk_mii_read(phyno, PHY_PHYIDR1));
+                       phytype = mii_send(mk_mii_read(phyno, MII_PHYSID1));
 #ifdef ET_DEBUG
                        printf("PHY type 0x%x pass %d type\n", phytype, pass);
 #endif
-                       if (phytype != 0xffff) {
-                               phyaddr = phyno;
-                               phytype <<= 16;
-                               phytype |=
-                                   mii_send(mk_mii_read(phyno, PHY_PHYIDR2));
+                       if (phytype == 0xffff)
+                               continue;
+                       phyaddr = phyno;
+                       phytype <<= 16;
+                       phytype |=
+                           mii_send(mk_mii_read(phyno, MII_PHYSID2));
 
 #ifdef ET_DEBUG
-                               printf("PHY @ 0x%x pass %d\n", phyno, pass);
+                       printf("PHY @ 0x%x pass %d\n", phyno, pass);
 #endif
 
-                               for (i = 0; i < (sizeof(phyinfo) / sizeof(phy_info_t)); i++) {
-                                       if (phyinfo[i].phyid == phytype) {
+                       for (i = 0; (i < ARRAY_SIZE(phyinfo))
+                               && (phyinfo[i].phyid != 0); i++) {
+                               if (phyinfo[i].phyid == phytype) {
 #ifdef ET_DEBUG
-                                               printf("phyid %x - %s\n",
-                                                      phyinfo[i].phyid,
-                                                      phyinfo[i].strid);
+                                       printf("phyid %x - %s\n",
+                                              phyinfo[i].phyid,
+                                              phyinfo[i].strid);
 #endif
-                                               strcpy(info->phy_name, phyinfo[i].strid);
-                                               info->phyname_init = 1;
-                                               found = 1;
-                                               break;
-                                       }
+                                       strcpy(info->phy_name, phyinfo[i].strid);
+                                       info->phyname_init = 1;
+                                       found = 1;
+                                       break;
                                }
+                       }
 
-                               if (!found) {
+                       if (!found) {
 #ifdef ET_DEBUG
-                                       printf("0x%08x\n", phytype);
+                               printf("0x%08x\n", phytype);
 #endif
-                                       strcpy(info->phy_name, "unknown");
-                                       info->phyname_init = 1;
-                                       break;
-                               }
+                               strcpy(info->phy_name, "unknown");
+                               info->phyname_init = 1;
+                               break;
                        }
                }
        }
@@ -226,7 +210,8 @@ void __mii_init(void)
        volatile FEC_T *fecp;
        struct eth_device *dev;
        int miispd = 0, i = 0;
-       u16 autoneg = 0;
+       u16 status = 0;
+       u16 linkgood = 0;
 
        /* retrieve from register structure */
        dev = eth_get_dev();
@@ -250,22 +235,32 @@ void __mii_init(void)
 
        info->phy_addr = mii_discover_phy(dev);
 
-#define AUTONEGLINK            (PHY_BMSR_AUTN_COMP | PHY_BMSR_LS)
        while (i < MCFFEC_TOUT_LOOP) {
-               autoneg = 0;
-               miiphy_read(dev->name, info->phy_addr, PHY_BMSR, &autoneg);
+               status = 0;
                i++;
-
-               if ((autoneg & AUTONEGLINK) == AUTONEGLINK)
+               /* Read PHY control register */
+               miiphy_read(dev->name, info->phy_addr, MII_BMCR, &status);
+
+               /* If phy set to autonegotiate, wait for autonegotiation done,
+                * if phy is not autonegotiating, just wait for link up.
+                */
+               if ((status & BMCR_ANENABLE) == BMCR_ANENABLE) {
+                       linkgood = (BMSR_ANEGCOMPLETE | BMSR_LSTATUS);
+               } else {
+                       linkgood = BMSR_LSTATUS;
+               }
+               /* Read PHY status register */
+               miiphy_read(dev->name, info->phy_addr, MII_BMSR, &status);
+               if ((status & linkgood) == linkgood)
                        break;
 
-               udelay(500);
+               udelay(1);
        }
        if (i >= MCFFEC_TOUT_LOOP) {
-               printf("Auto Negotiation not complete\n");
+               printf("Link UP timeout\n");
        }
 
-       /* adapt to the half/full speed settings */
+       /* adapt to the duplex and speed settings of the phy */
        info->dup_spd = miiphy_duplex(dev->name, info->phy_addr) << 16;
        info->dup_spd |= miiphy_speed(dev->name, info->phy_addr);
 }
@@ -281,8 +276,7 @@ void __mii_init(void)
  *       Otherwise they hang in mii_send() !!! Sorry!
  */
 
-int mcffec_miiphy_read(char *devname, unsigned char addr, unsigned char reg,
-                      unsigned short *value)
+int mcffec_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
 {
        short rdreg;            /* register working value */
 
@@ -291,31 +285,23 @@ int mcffec_miiphy_read(char *devname, unsigned char addr, unsigned char reg,
 #endif
        rdreg = mii_send(mk_mii_read(addr, reg));
 
-       *value = rdreg;
-
 #ifdef MII_DEBUG
-       printf("0x%04x\n", *value);
+       printf("0x%04x\n", rdreg);
 #endif
 
-       return 0;
+       return rdreg;
 }
 
-int mcffec_miiphy_write(char *devname, unsigned char addr, unsigned char reg,
-                       unsigned short value)
+int mcffec_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
+                       u16 value)
 {
-       short rdreg;            /* register working value */
-
 #ifdef MII_DEBUG
-       printf("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
+       printf("miiphy_write(0x%x) @ 0x%x = 0x%04x\n", reg, addr, value);
 #endif
 
-       rdreg = mii_send(mk_mii_write(addr, reg, value));
-
-#ifdef MII_DEBUG
-       printf("0x%04x\n", value);
-#endif
+       mii_send(mk_mii_write(addr, reg, value));
 
        return 0;
 }
 
-#endif                         /* CONFIG_CMD_NET, FEC_ENET & NET_MULTI */
+#endif                         /* CONFIG_CMD_NET */