3 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * This provides a bit-banged interface to the ethernet MII management
32 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
34 /*****************************************************************************
36 * Read the OUI, manufacture's model number, and revision number.
38 * OUI: 22 bits (unsigned int)
39 * Model: 6 bits (unsigned char)
40 * Revision: 4 bits (unsigned char)
45 int miiphy_info (unsigned char addr,
47 unsigned char *model, unsigned char *rev)
52 if (miiphy_read (addr, PHY_PHYIDR2, &tmp) != 0) {
54 printf ("PHY ID register 2 read failed\n");
61 printf ("PHY_PHYIDR2 @ 0x%x = 0x%04x\n", addr, reg);
64 /* No physical device present at this address */
68 if (miiphy_read (addr, PHY_PHYIDR1, &tmp) != 0) {
70 printf ("PHY ID register 1 read failed\n");
76 printf ("PHY_PHYIDR[1,2] @ 0x%x = 0x%08x\n", addr, reg);
79 *model = (unsigned char) ((reg >> 4) & 0x0000003F);
80 *rev = (unsigned char) ( reg & 0x0000000F);
85 /*****************************************************************************
91 int miiphy_reset (unsigned char addr)
96 if (miiphy_write (addr, PHY_BMCR, 0x8000) != 0) {
98 printf ("PHY reset failed\n");
102 #ifdef CONFIG_PHY_RESET_DELAY
103 udelay (CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
106 * Poll the control register for the reset bit to go to 0 (it is
107 * auto-clearing). This should happen within 0.5 seconds per the
112 while (((reg & 0x8000) != 0) && (loop_cnt++ < 1000000)) {
113 if (miiphy_read (addr, PHY_BMCR, ®) != 0) {
115 printf ("PHY status read failed\n");
120 if ((reg & 0x8000) == 0) {
123 printf ("PHY reset timed out\n");
130 /*****************************************************************************
132 * Determine the ethernet speed (10/100).
134 int miiphy_speed (unsigned char addr)
138 if (miiphy_read (addr, PHY_ANLPAR, ®)) {
139 printf ("PHY speed1 read failed, assuming 10bT\n");
143 if ((reg & PHY_ANLPAR_100) != 0) {
151 /*****************************************************************************
153 * Determine full/half duplex.
155 int miiphy_duplex (unsigned char addr)
159 if (miiphy_read (addr, PHY_ANLPAR, ®)) {
160 printf ("PHY duplex read failed, assuming half duplex\n");
164 if ((reg & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD)) != 0) {
171 #ifdef CFG_FAULT_ECHO_LINK_DOWN
172 /*****************************************************************************
174 * Determine link status
176 int miiphy_link (unsigned char addr)
180 if (miiphy_read (addr, PHY_BMSR, ®)) {
181 printf ("PHY_BMSR read failed, assuming no link\n");
185 /* Determine if a link is active */
186 if ((reg & PHY_BMSR_LS) != 0) {
194 #endif /* CONFIG_MII || (CONFIG_COMMANDS & CFG_CMD_MII) */