blob: 4216f0bd41be79d2a564a5338890a3422e962492 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*-----------------------------------------------------------------------------+
2 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +02003 | This source code has been made available to you by IBM on an AS-IS
4 | basis. Anyone receiving this source is licensed under IBM
5 | copyrights to use it in any way he or she deems fit, including
6 | copying it, modifying it, compiling it, and redistributing it either
7 | with or without modifications. No license under IBM patents or
8 | patent applications is to be implied by the copyright license.
wdenkaffae2b2002-08-17 09:36:01 +00009 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020010 | Any user of this software should understand that IBM cannot provide
11 | technical support for this software and will not be responsible for
12 | any consequences resulting from the use of this software.
wdenkaffae2b2002-08-17 09:36:01 +000013 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020014 | Any person who transfers this source code or any derivative work
15 | must include the IBM copyright notice, this paragraph, and the
16 | preceding two paragraphs in the transferred software.
wdenkaffae2b2002-08-17 09:36:01 +000017 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020018 | COPYRIGHT I B M CORPORATION 1995
19 | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
wdenkaffae2b2002-08-17 09:36:01 +000020 +-----------------------------------------------------------------------------*/
21/*-----------------------------------------------------------------------------+
22 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020023 | File Name: miiphy.c
wdenkaffae2b2002-08-17 09:36:01 +000024 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020025 | Function: This module has utilities for accessing the MII PHY through
wdenkaffae2b2002-08-17 09:36:01 +000026 | the EMAC3 macro.
27 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020028 | Author: Mark Wisner
wdenkaffae2b2002-08-17 09:36:01 +000029 |
wdenkaffae2b2002-08-17 09:36:01 +000030 +-----------------------------------------------------------------------------*/
31
32#include <common.h>
33#include <asm/processor.h>
Stefan Roese2d834762007-10-23 14:03:17 +020034#include <asm/io.h>
wdenkaffae2b2002-08-17 09:36:01 +000035#include <ppc_asm.tmpl>
36#include <commproc.h>
Stefan Roesed6c61aa2005-08-16 18:18:00 +020037#include <ppc4xx_enet.h>
wdenkaffae2b2002-08-17 09:36:01 +000038#include <405_mal.h>
39#include <miiphy.h>
40
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020041#undef ET_DEBUG
wdenkaffae2b2002-08-17 09:36:01 +000042/***********************************************************/
Stefan Roesed6c61aa2005-08-16 18:18:00 +020043/* Dump out to the screen PHY regs */
wdenkaffae2b2002-08-17 09:36:01 +000044/***********************************************************/
45
Marian Balakowicz63ff0042005-10-28 22:30:33 +020046void miiphy_dump (char *devname, unsigned char addr)
wdenkaffae2b2002-08-17 09:36:01 +000047{
48 unsigned long i;
49 unsigned short data;
50
wdenkaffae2b2002-08-17 09:36:01 +000051 for (i = 0; i < 0x1A; i++) {
Marian Balakowicz63ff0042005-10-28 22:30:33 +020052 if (miiphy_read (devname, addr, i, &data)) {
wdenkaffae2b2002-08-17 09:36:01 +000053 printf ("read error for reg %lx\n", i);
54 return;
55 }
56 printf ("Phy reg %lx ==> %4x\n", i, data);
57
58 /* jump to the next set of regs */
59 if (i == 0x07)
60 i = 0x0f;
61
Stefan Roesed6c61aa2005-08-16 18:18:00 +020062 } /* end for loop */
63} /* end dump */
wdenkaffae2b2002-08-17 09:36:01 +000064
wdenkaffae2b2002-08-17 09:36:01 +000065/***********************************************************/
Stefan Roesed6c61aa2005-08-16 18:18:00 +020066/* (Re)start autonegotiation */
wdenkaffae2b2002-08-17 09:36:01 +000067/***********************************************************/
Marian Balakowicz63ff0042005-10-28 22:30:33 +020068int phy_setup_aneg (char *devname, unsigned char addr)
wdenkaffae2b2002-08-17 09:36:01 +000069{
Larry Johnsonc3485782007-12-27 10:50:55 -050070 u16 bmcr;
wdenkaffae2b2002-08-17 09:36:01 +000071
Larry Johnsonc3485782007-12-27 10:50:55 -050072#if defined(CONFIG_PHY_DYNAMIC_ANEG)
73 /*
74 * Set up advertisement based on capablilities reported by the PHY.
75 * This should work for both copper and fiber.
76 */
77 u16 bmsr;
78#if defined(CONFIG_PHY_GIGE)
79 u16 exsr = 0x0000;
80#endif
81
82 miiphy_read (devname, addr, PHY_BMSR, &bmsr);
83
84#if defined(CONFIG_PHY_GIGE)
85 if (bmsr & PHY_BMSR_EXT_STAT)
86 miiphy_read (devname, addr, PHY_EXSR, &exsr);
87
88 if (exsr & (PHY_EXSR_1000XF | PHY_EXSR_1000XH)) {
89 /* 1000BASE-X */
90 u16 anar = 0x0000;
91
92 if (exsr & PHY_EXSR_1000XF)
93 anar |= PHY_X_ANLPAR_FD;
94
95 if (exsr & PHY_EXSR_1000XH)
96 anar |= PHY_X_ANLPAR_HD;
97
98 miiphy_write (devname, addr, PHY_ANAR, anar);
99 } else
100#endif
101 {
102 u16 anar, btcr;
103
104 miiphy_read (devname, addr, PHY_ANAR, &anar);
105 anar &= ~(0x5000 | PHY_ANLPAR_T4 | PHY_ANLPAR_TXFD |
106 PHY_ANLPAR_TX | PHY_ANLPAR_10FD | PHY_ANLPAR_10);
107
108 miiphy_read (devname, addr, PHY_1000BTCR, &btcr);
109 btcr &= ~(0x00FF | PHY_1000BTCR_1000FD | PHY_1000BTCR_1000HD);
110
111 if (bmsr & PHY_BMSR_100T4)
112 anar |= PHY_ANLPAR_T4;
113
114 if (bmsr & PHY_BMSR_100TXF)
115 anar |= PHY_ANLPAR_TXFD;
116
117 if (bmsr & PHY_BMSR_100TXH)
118 anar |= PHY_ANLPAR_TX;
119
120 if (bmsr & PHY_BMSR_10TF)
121 anar |= PHY_ANLPAR_10FD;
122
123 if (bmsr & PHY_BMSR_10TH)
124 anar |= PHY_ANLPAR_10;
125
126 miiphy_write (devname, addr, PHY_ANAR, anar);
127
128#if defined(CONFIG_PHY_GIGE)
129 if (exsr & PHY_EXSR_1000TF)
130 btcr |= PHY_1000BTCR_1000FD;
131
132 if (exsr & PHY_EXSR_1000TH)
133 btcr |= PHY_1000BTCR_1000HD;
134
135 miiphy_write (devname, addr, PHY_1000BTCR, btcr);
136#endif
137 }
138
139#else /* defined(CONFIG_PHY_DYNAMIC_ANEG) */
140 /*
141 * Set up standard advertisement
142 */
143 u16 adv;
144
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200145 miiphy_read (devname, addr, PHY_ANAR, &adv);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200146 adv |= (PHY_ANLPAR_ACK | PHY_ANLPAR_RF | PHY_ANLPAR_T4 |
147 PHY_ANLPAR_TXFD | PHY_ANLPAR_TX | PHY_ANLPAR_10FD |
148 PHY_ANLPAR_10);
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200149 miiphy_write (devname, addr, PHY_ANAR, adv);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200150
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200151 miiphy_read (devname, addr, PHY_1000BTCR, &adv);
152 adv |= (0x0300);
153 miiphy_write (devname, addr, PHY_1000BTCR, adv);
154
Larry Johnsonc3485782007-12-27 10:50:55 -0500155#endif /* defined(CONFIG_PHY_DYNAMIC_ANEG) */
156
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200157 /* Start/Restart aneg */
Larry Johnsonc3485782007-12-27 10:50:55 -0500158 miiphy_read (devname, addr, PHY_BMCR, &bmcr);
159 bmcr |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG);
160 miiphy_write (devname, addr, PHY_BMCR, bmcr);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200161
162 return 0;
163}
164
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200165/***********************************************************/
166/* read a phy reg and return the value with a rc */
167/***********************************************************/
168unsigned int miiphy_getemac_offset (void)
169{
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200170#if (defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)) && defined(CONFIG_NET_MULTI)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200171 unsigned long zmii;
172 unsigned long eoffset;
173
174 /* Need to find out which mdi port we're using */
Stefan Roese2d834762007-10-23 14:03:17 +0200175 zmii = in_be32((void *)ZMII_FER);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200176
Larry Johnsonc3485782007-12-27 10:50:55 -0500177 if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200178 /* using port 0 */
179 eoffset = 0;
Larry Johnsonc3485782007-12-27 10:50:55 -0500180
181 else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200182 /* using port 1 */
183 eoffset = 0x100;
Larry Johnsonc3485782007-12-27 10:50:55 -0500184
185 else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200186 /* using port 2 */
187 eoffset = 0x400;
Larry Johnsonc3485782007-12-27 10:50:55 -0500188
189 else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200190 /* using port 3 */
191 eoffset = 0x600;
Larry Johnsonc3485782007-12-27 10:50:55 -0500192
193 else {
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200194 /* None of the mdi ports are enabled! */
195 /* enable port 0 */
196 zmii |= ZMII_FER_MDI << ZMII_FER_V (0);
Stefan Roese2d834762007-10-23 14:03:17 +0200197 out_be32((void *)ZMII_FER, zmii);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200198 eoffset = 0;
199 /* need to soft reset port 0 */
Stefan Roese2d834762007-10-23 14:03:17 +0200200 zmii = in_be32((void *)EMAC_M0);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200201 zmii |= EMAC_M0_SRST;
Stefan Roese2d834762007-10-23 14:03:17 +0200202 out_be32((void *)EMAC_M0, zmii);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200203 }
204
205 return (eoffset);
206#else
Stefan Roesedbbd1252007-10-05 17:10:59 +0200207
208#if defined(CONFIG_NET_MULTI) && defined(CONFIG_405EX)
209 unsigned long rgmii;
210 int devnum = 1;
211
Stefan Roese2d834762007-10-23 14:03:17 +0200212 rgmii = in_be32((void *)RGMII_FER);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200213 if (rgmii & (1 << (19 - devnum)))
214 return 0x100;
215#endif
216
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200217 return 0;
218#endif
219}
220
Larry Johnsonc3485782007-12-27 10:50:55 -0500221int emac4xx_miiphy_read (char *devname, unsigned char addr, unsigned char reg,
222 unsigned short *value)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200223{
224 unsigned long sta_reg; /* STA scratch area */
225 unsigned long i;
226 unsigned long emac_reg;
227
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200228 emac_reg = miiphy_getemac_offset ();
wdenkaffae2b2002-08-17 09:36:01 +0000229 /* see if it is ready for 1000 nsec */
230 i = 0;
231
232 /* see if it is ready for sec */
Larry Johnsonc3485782007-12-27 10:50:55 -0500233 while ((in_be32((void *)EMAC_STACR + emac_reg) & EMAC_STACR_OC) ==
234 EMAC_STACR_OC_MASK) {
wdenkaffae2b2002-08-17 09:36:01 +0000235 udelay (7);
236 if (i > 5) {
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200237#ifdef ET_DEBUG
Stefan Roese2d834762007-10-23 14:03:17 +0200238 sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200239 printf ("read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
wdenkaffae2b2002-08-17 09:36:01 +0000240 printf ("read err 1\n");
stroese38a95192003-12-09 14:57:03 +0000241#endif
wdenkaffae2b2002-08-17 09:36:01 +0000242 return -1;
243 }
244 i++;
245 }
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200246 sta_reg = reg; /* reg address */
wdenkaffae2b2002-08-17 09:36:01 +0000247 /* set clock (50Mhz) and read flags */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200248#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200249 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
250 defined(CONFIG_405EX)
Larry Johnsonc3485782007-12-27 10:50:55 -0500251#if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */
252 sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_READ;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200253#else
Larry Johnsonc3485782007-12-27 10:50:55 -0500254 sta_reg |= EMAC_STACR_READ;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200255#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200256#else
wdenkaffae2b2002-08-17 09:36:01 +0000257 sta_reg = (sta_reg | EMAC_STACR_READ) & ~EMAC_STACR_CLK_100MHZ;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200258#endif
259
Stefan Roese887e2ec2006-09-07 11:51:23 +0200260#if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \
261 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200262 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
263 !defined(CONFIG_405EX)
wdenk12f34242003-09-02 22:48:03 +0000264 sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ;
wdenk093ae272003-09-02 23:08:13 +0000265#endif
wdenkaffae2b2002-08-17 09:36:01 +0000266 sta_reg = sta_reg | (addr << 5); /* Phy address */
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200267 sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */
Stefan Roese2d834762007-10-23 14:03:17 +0200268 out_be32((void *)EMAC_STACR + emac_reg, sta_reg);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200269#ifdef ET_DEBUG
wdenkaffae2b2002-08-17 09:36:01 +0000270 printf ("a2: write: EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
271#endif
272
Stefan Roese2d834762007-10-23 14:03:17 +0200273 sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200274#ifdef ET_DEBUG
Larry Johnsonc3485782007-12-27 10:50:55 -0500275 printf ("a21: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200276#endif
wdenkaffae2b2002-08-17 09:36:01 +0000277 i = 0;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200278 while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) {
wdenkaffae2b2002-08-17 09:36:01 +0000279 udelay (7);
Larry Johnsonc3485782007-12-27 10:50:55 -0500280 if (i > 5)
wdenkaffae2b2002-08-17 09:36:01 +0000281 return -1;
Larry Johnsonc3485782007-12-27 10:50:55 -0500282
wdenkaffae2b2002-08-17 09:36:01 +0000283 i++;
Stefan Roese2d834762007-10-23 14:03:17 +0200284 sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200285#ifdef ET_DEBUG
286 printf ("a22: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
287#endif
wdenkaffae2b2002-08-17 09:36:01 +0000288 }
Larry Johnsonc3485782007-12-27 10:50:55 -0500289 if ((sta_reg & EMAC_STACR_PHYE) != 0)
wdenkaffae2b2002-08-17 09:36:01 +0000290 return -1;
wdenkaffae2b2002-08-17 09:36:01 +0000291
Larry Johnsonc3485782007-12-27 10:50:55 -0500292 *value = *(short *)(&sta_reg);
wdenkaffae2b2002-08-17 09:36:01 +0000293 return 0;
294
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200295} /* phy_read */
wdenkaffae2b2002-08-17 09:36:01 +0000296
wdenkaffae2b2002-08-17 09:36:01 +0000297/***********************************************************/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200298/* write a phy reg and return the value with a rc */
wdenkaffae2b2002-08-17 09:36:01 +0000299/***********************************************************/
300
Larry Johnsonc3485782007-12-27 10:50:55 -0500301int emac4xx_miiphy_write (char *devname, unsigned char addr, unsigned char reg,
302 unsigned short value)
wdenkaffae2b2002-08-17 09:36:01 +0000303{
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200304 unsigned long sta_reg; /* STA scratch area */
wdenkaffae2b2002-08-17 09:36:01 +0000305 unsigned long i;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200306 unsigned long emac_reg;
wdenkaffae2b2002-08-17 09:36:01 +0000307
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200308 emac_reg = miiphy_getemac_offset ();
wdenkaffae2b2002-08-17 09:36:01 +0000309 /* see if it is ready for 1000 nsec */
310 i = 0;
311
Larry Johnsonc3485782007-12-27 10:50:55 -0500312 while ((in_be32((void *)EMAC_STACR + emac_reg) & EMAC_STACR_OC) ==
313 EMAC_STACR_OC_MASK) {
wdenkaffae2b2002-08-17 09:36:01 +0000314 if (i > 5)
315 return -1;
Larry Johnsonc3485782007-12-27 10:50:55 -0500316
wdenkaffae2b2002-08-17 09:36:01 +0000317 udelay (7);
318 i++;
319 }
320 sta_reg = 0;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200321 sta_reg = reg; /* reg address */
wdenkaffae2b2002-08-17 09:36:01 +0000322 /* set clock (50Mhz) and read flags */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200323#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200324 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
325 defined(CONFIG_405EX)
Larry Johnsonc3485782007-12-27 10:50:55 -0500326#if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */
327 sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_WRITE;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200328#else
Larry Johnsonc3485782007-12-27 10:50:55 -0500329 sta_reg |= EMAC_STACR_WRITE;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200330#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200331#else
wdenkaffae2b2002-08-17 09:36:01 +0000332 sta_reg = (sta_reg | EMAC_STACR_WRITE) & ~EMAC_STACR_CLK_100MHZ;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200333#endif
334
Stefan Roese887e2ec2006-09-07 11:51:23 +0200335#if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \
336 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200337 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
338 !defined(CONFIG_405EX)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200339 sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; /* Set clock frequency (PLB freq. dependend) */
wdenk093ae272003-09-02 23:08:13 +0000340#endif
Larry Johnsonc3485782007-12-27 10:50:55 -0500341 sta_reg = sta_reg | ((unsigned long)addr << 5); /* Phy address */
342 sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */
wdenkaffae2b2002-08-17 09:36:01 +0000343 memcpy (&sta_reg, &value, 2); /* put in data */
344
Stefan Roese2d834762007-10-23 14:03:17 +0200345 out_be32((void *)EMAC_STACR + emac_reg, sta_reg);
wdenkaffae2b2002-08-17 09:36:01 +0000346
wdenkaffae2b2002-08-17 09:36:01 +0000347 /* wait for completion */
348 i = 0;
Stefan Roese2d834762007-10-23 14:03:17 +0200349 sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200350#ifdef ET_DEBUG
Larry Johnsonc3485782007-12-27 10:50:55 -0500351 printf ("a31: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200352#endif
353 while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) {
wdenkaffae2b2002-08-17 09:36:01 +0000354 udelay (7);
355 if (i > 5)
356 return -1;
Larry Johnsonc3485782007-12-27 10:50:55 -0500357
wdenkaffae2b2002-08-17 09:36:01 +0000358 i++;
Stefan Roese2d834762007-10-23 14:03:17 +0200359 sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200360#ifdef ET_DEBUG
361 printf ("a32: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
362#endif
wdenkaffae2b2002-08-17 09:36:01 +0000363 }
364
365 if ((sta_reg & EMAC_STACR_PHYE) != 0)
366 return -1;
Larry Johnsonc3485782007-12-27 10:50:55 -0500367
wdenkaffae2b2002-08-17 09:36:01 +0000368 return 0;
369
Larry Johnsonc3485782007-12-27 10:50:55 -0500370} /* phy_write */