AX88180: improve phy searching
authorMike Frysinger <vapier@gentoo.org>
Mon, 10 May 2010 20:10:00 +0000 (16:10 -0400)
committerBen Warren <biggerbadderben@gmail.com>
Mon, 12 Jul 2010 07:14:28 +0000 (00:14 -0700)
Rather than hardcode specific phy addresses, search the possible phy
address space to find the first available phy.  Also respect the normal
CONFIG_PHY_ADDR option for board porters to pick a specific address.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
drivers/net/ax88180.c
drivers/net/ax88180.h

index 5d12fcf0319ddd77ffef7f654da3283f3e5b301a..6e788a06410c2f09b85bc761126d5e34edf118e5 100644 (file)
@@ -255,49 +255,60 @@ static int ax88180_phy_initial (struct eth_device *dev)
 {
        struct ax88180_private *priv = (struct ax88180_private *)dev->priv;
        unsigned long tmp_regval;
+       unsigned short phyaddr;
 
-       /* Check avaliable PHY chipset  */
-       priv->PhyAddr = MARVELL_88E1111_PHYADDR;
-       priv->PhyID0 = ax88180_mdio_read (dev, PHYIDR0);
-
-       if (priv->PhyID0 == MARVELL_88E1111_PHYIDR0) {
-
-               debug ("ax88180: Found Marvell 88E1111 PHY."
-                      " (PHY Addr=0x%x)\n", priv->PhyAddr);
-
-               tmp_regval = ax88180_mdio_read (dev, M88_EXT_SSR);
-               if ((tmp_regval & HWCFG_MODE_MASK) == RGMII_COPPER_MODE) {
-
-                       ax88180_mdio_write (dev, M88_EXT_SCR, DEFAULT_EXT_SCR);
-                       if (ax88180_phy_reset (dev) < 0)
-                               return 0;
-                       ax88180_mdio_write (dev, M88_IER, LINK_CHANGE_INT);
-               }
-       } else {
+       /* Search for first avaliable PHY chipset */
+#ifdef CONFIG_PHY_ADDR
+       phyaddr = CONFIG_PHY_ADDR;
+#else
+       for (phyaddr = 0; phyaddr < 32; ++phyaddr)
+#endif
+       {
+               priv->PhyAddr = phyaddr;
+               priv->PhyID0 = ax88180_mdio_read(dev, PHYIDR0);
+
+               switch (priv->PhyID0) {
+               case MARVELL_88E1111_PHYIDR0:
+                       debug("ax88180: Found Marvell 88E1111 PHY."
+                             " (PHY Addr=0x%x)\n", priv->PhyAddr);
+
+                       tmp_regval = ax88180_mdio_read(dev, M88_EXT_SSR);
+                       if ((tmp_regval & HWCFG_MODE_MASK) != RGMII_COPPER_MODE) {
+                               ax88180_mdio_write(dev, M88_EXT_SCR, DEFAULT_EXT_SCR);
+                               if (ax88180_phy_reset(dev) < 0)
+                                       return 0;
+                               ax88180_mdio_write(dev, M88_IER, LINK_CHANGE_INT);
+                       }
 
-               priv->PhyAddr = CICADA_CIS8201_PHYADDR;
-               priv->PhyID0 = ax88180_mdio_read (dev, PHYIDR0);
+                       return 1;
 
-               if (priv->PhyID0 == CICADA_CIS8201_PHYIDR0) {
+               case CICADA_CIS8201_PHYIDR0:
+                       debug("ax88180: Found CICADA CIS8201 PHY"
+                             " chipset. (PHY Addr=0x%x)\n", priv->PhyAddr);
 
-                       debug ("ax88180: Found CICADA CIS8201 PHY"
-                              " chipset. (PHY Addr=0x%x)\n", priv->PhyAddr);
-                       ax88180_mdio_write (dev, CIS_IMR,
+                       ax88180_mdio_write(dev, CIS_IMR,
                                            (CIS_INT_ENABLE | LINK_CHANGE_INT));
 
                        /* Set CIS_SMI_PRIORITY bit before force the media mode */
-                       tmp_regval =
-                           ax88180_mdio_read (dev, CIS_AUX_CTRL_STATUS);
+                       tmp_regval = ax88180_mdio_read(dev, CIS_AUX_CTRL_STATUS);
                        tmp_regval &= ~CIS_SMI_PRIORITY;
-                       ax88180_mdio_write (dev, CIS_AUX_CTRL_STATUS,
-                                           tmp_regval);
-               } else {
-                       printf ("ax88180: Unknown PHY chipset!!\n");
-                       return 0;
+                       ax88180_mdio_write(dev, CIS_AUX_CTRL_STATUS, tmp_regval);
+
+                       return 1;
+
+               case 0xffff:
+                       /* No PHY at this addr */
+                       break;
+
+               default:
+                       printf("ax88180: Unknown PHY chipset %#x at addr %#x\n",
+                              priv->PhyID0, priv->PhyAddr);
+                       break;
                }
        }
 
-       return 1;
+       printf("ax88180: Unknown PHY chipset!!\n");
+       return 0;
 }
 
 static void ax88180_media_config (struct eth_device *dev)
@@ -345,12 +356,16 @@ static void ax88180_media_config (struct eth_device *dev)
                       (unsigned int)bmcr_val, (unsigned int)bmsr_val);
 
                /* Get real media mode here */
-               if (priv->PhyID0 == MARVELL_88E1111_PHYIDR0) {
-                       RealMediaMode = get_MarvellPHY_media_mode (dev);
-               } else if (priv->PhyID0 == CICADA_CIS8201_PHYIDR0) {
-                       RealMediaMode = get_CicadaPHY_media_mode (dev);
-               } else {
+               switch (priv->PhyID0) {
+               case MARVELL_88E1111_PHYIDR0:
+                       RealMediaMode = get_MarvellPHY_media_mode(dev);
+                       break;
+               case CICADA_CIS8201_PHYIDR0:
+                       RealMediaMode = get_CicadaPHY_media_mode(dev);
+                       break;
+               default:
                        RealMediaMode = MEDIA_1000FULL;
+                       break;
                }
 
                priv->LinkState = INS_LINK_UP;
index d2113df4bd152ca9a3d45de77070264cd15e4965..77bab5f6e66c182ccd24958638f6162154709539 100644 (file)
@@ -63,10 +63,8 @@ struct ax88180_private {
 /* Max Rx Jumbo size is 15K Bytes */
 #define MAX_RX_SIZE                    0x3C00
 
-#define MARVELL_88E1111_PHYADDR        0x18
 #define MARVELL_88E1111_PHYIDR0        0x0141
 
-#define CICADA_CIS8201_PHYADDR 0x01
 #define CICADA_CIS8201_PHYIDR0         0x000F
 
 #define MEDIA_AUTO                     0