blob: 297155fdafa064b955e53e9832de93bfb0cfb85b [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*-----------------------------------------------------------------------------+
Josh Boyer31773492009-08-07 13:53:20 -04002 | This source code is dual-licensed. You may use it under the terms of the
3 | GNU General Public License version 2, or under the license below.
wdenkaffae2b2002-08-17 09:36:01 +00004 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +02005 | This source code has been made available to you by IBM on an AS-IS
6 | basis. Anyone receiving this source is licensed under IBM
7 | copyrights to use it in any way he or she deems fit, including
8 | copying it, modifying it, compiling it, and redistributing it either
9 | with or without modifications. No license under IBM patents or
10 | patent applications is to be implied by the copyright license.
wdenkaffae2b2002-08-17 09:36:01 +000011 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020012 | Any user of this software should understand that IBM cannot provide
13 | technical support for this software and will not be responsible for
14 | any consequences resulting from the use of this software.
wdenkaffae2b2002-08-17 09:36:01 +000015 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020016 | Any person who transfers this source code or any derivative work
17 | must include the IBM copyright notice, this paragraph, and the
18 | preceding two paragraphs in the transferred software.
wdenkaffae2b2002-08-17 09:36:01 +000019 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020020 | COPYRIGHT I B M CORPORATION 1995
21 | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
wdenkaffae2b2002-08-17 09:36:01 +000022 +-----------------------------------------------------------------------------*/
23/*-----------------------------------------------------------------------------+
24 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020025 | File Name: miiphy.c
wdenkaffae2b2002-08-17 09:36:01 +000026 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020027 | Function: This module has utilities for accessing the MII PHY through
wdenkaffae2b2002-08-17 09:36:01 +000028 | the EMAC3 macro.
29 |
Stefan Roesed6c61aa2005-08-16 18:18:00 +020030 | Author: Mark Wisner
wdenkaffae2b2002-08-17 09:36:01 +000031 |
wdenkaffae2b2002-08-17 09:36:01 +000032 +-----------------------------------------------------------------------------*/
33
Stefan Roesec3307fa2008-02-19 21:58:25 +010034/* define DEBUG for debugging output (obviously ;-)) */
35#if 0
36#define DEBUG
37#endif
38
wdenkaffae2b2002-08-17 09:36:01 +000039#include <common.h>
40#include <asm/processor.h>
Stefan Roese2d834762007-10-23 14:03:17 +020041#include <asm/io.h>
wdenkaffae2b2002-08-17 09:36:01 +000042#include <ppc_asm.tmpl>
43#include <commproc.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020044#include <asm/ppc4xx-emac.h>
45#include <asm/ppc4xx-mal.h>
wdenkaffae2b2002-08-17 09:36:01 +000046#include <miiphy.h>
47
Stefan Roesec3307fa2008-02-19 21:58:25 +010048#if !defined(CONFIG_PHY_CLK_FREQ)
49#define CONFIG_PHY_CLK_FREQ 0
50#endif
51
wdenkaffae2b2002-08-17 09:36:01 +000052/***********************************************************/
Stefan Roesed6c61aa2005-08-16 18:18:00 +020053/* Dump out to the screen PHY regs */
wdenkaffae2b2002-08-17 09:36:01 +000054/***********************************************************/
55
Marian Balakowicz63ff0042005-10-28 22:30:33 +020056void miiphy_dump (char *devname, unsigned char addr)
wdenkaffae2b2002-08-17 09:36:01 +000057{
58 unsigned long i;
59 unsigned short data;
60
wdenkaffae2b2002-08-17 09:36:01 +000061 for (i = 0; i < 0x1A; i++) {
Marian Balakowicz63ff0042005-10-28 22:30:33 +020062 if (miiphy_read (devname, addr, i, &data)) {
wdenkaffae2b2002-08-17 09:36:01 +000063 printf ("read error for reg %lx\n", i);
64 return;
65 }
66 printf ("Phy reg %lx ==> %4x\n", i, data);
67
68 /* jump to the next set of regs */
69 if (i == 0x07)
70 i = 0x0f;
71
Stefan Roesed6c61aa2005-08-16 18:18:00 +020072 } /* end for loop */
73} /* end dump */
wdenkaffae2b2002-08-17 09:36:01 +000074
wdenkaffae2b2002-08-17 09:36:01 +000075/***********************************************************/
Stefan Roesed6c61aa2005-08-16 18:18:00 +020076/* (Re)start autonegotiation */
wdenkaffae2b2002-08-17 09:36:01 +000077/***********************************************************/
Marian Balakowicz63ff0042005-10-28 22:30:33 +020078int phy_setup_aneg (char *devname, unsigned char addr)
wdenkaffae2b2002-08-17 09:36:01 +000079{
Larry Johnsonc3485782007-12-27 10:50:55 -050080 u16 bmcr;
wdenkaffae2b2002-08-17 09:36:01 +000081
Larry Johnsonc3485782007-12-27 10:50:55 -050082#if defined(CONFIG_PHY_DYNAMIC_ANEG)
83 /*
84 * Set up advertisement based on capablilities reported by the PHY.
85 * This should work for both copper and fiber.
86 */
87 u16 bmsr;
88#if defined(CONFIG_PHY_GIGE)
89 u16 exsr = 0x0000;
90#endif
91
Mike Frysinger8ef583a2010-12-23 15:40:12 -050092 miiphy_read (devname, addr, MII_BMSR, &bmsr);
Larry Johnsonc3485782007-12-27 10:50:55 -050093
94#if defined(CONFIG_PHY_GIGE)
Mike Frysinger8ef583a2010-12-23 15:40:12 -050095 if (bmsr & BMSR_ESTATEN)
96 miiphy_read (devname, addr, MII_ESTATUS, &exsr);
Larry Johnsonc3485782007-12-27 10:50:55 -050097
Mike Frysinger8ef583a2010-12-23 15:40:12 -050098 if (exsr & (ESTATUS_1000XF | ESTATUS_1000XH)) {
Larry Johnsonc3485782007-12-27 10:50:55 -050099 /* 1000BASE-X */
100 u16 anar = 0x0000;
101
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500102 if (exsr & ESTATUS_1000XF)
Stefan Roesec722c702011-01-10 12:56:13 +0100103 anar |= ADVERTISE_1000XFULL;
Larry Johnsonc3485782007-12-27 10:50:55 -0500104
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500105 if (exsr & ESTATUS_1000XH)
106 anar |= ADVERTISE_1000XHALF;
Larry Johnsonc3485782007-12-27 10:50:55 -0500107
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500108 miiphy_write (devname, addr, MII_ADVERTISE, anar);
Larry Johnsonc3485782007-12-27 10:50:55 -0500109 } else
110#endif
111 {
112 u16 anar, btcr;
113
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500114 miiphy_read (devname, addr, MII_ADVERTISE, &anar);
115 anar &= ~(0x5000 | LPA_100BASE4 | LPA_100FULL |
116 LPA_100HALF | LPA_10FULL | LPA_10HALF);
Larry Johnsonc3485782007-12-27 10:50:55 -0500117
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500118 miiphy_read (devname, addr, MII_CTRL1000, &btcr);
Larry Johnsonc3485782007-12-27 10:50:55 -0500119 btcr &= ~(0x00FF | PHY_1000BTCR_1000FD | PHY_1000BTCR_1000HD);
120
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500121 if (bmsr & BMSR_100BASE4)
122 anar |= LPA_100BASE4;
Larry Johnsonc3485782007-12-27 10:50:55 -0500123
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500124 if (bmsr & BMSR_100FULL)
125 anar |= LPA_100FULL;
Larry Johnsonc3485782007-12-27 10:50:55 -0500126
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500127 if (bmsr & BMSR_100HALF)
128 anar |= LPA_100HALF;
Larry Johnsonc3485782007-12-27 10:50:55 -0500129
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500130 if (bmsr & BMSR_10FULL)
131 anar |= LPA_10FULL;
Larry Johnsonc3485782007-12-27 10:50:55 -0500132
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500133 if (bmsr & BMSR_10HALF)
134 anar |= LPA_10HALF;
Larry Johnsonc3485782007-12-27 10:50:55 -0500135
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500136 miiphy_write (devname, addr, MII_ADVERTISE, anar);
Larry Johnsonc3485782007-12-27 10:50:55 -0500137
138#if defined(CONFIG_PHY_GIGE)
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500139 if (exsr & ESTATUS_1000_TFULL)
Larry Johnsonc3485782007-12-27 10:50:55 -0500140 btcr |= PHY_1000BTCR_1000FD;
141
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500142 if (exsr & ESTATUS_1000_THALF)
Larry Johnsonc3485782007-12-27 10:50:55 -0500143 btcr |= PHY_1000BTCR_1000HD;
144
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500145 miiphy_write (devname, addr, MII_CTRL1000, btcr);
Larry Johnsonc3485782007-12-27 10:50:55 -0500146#endif
147 }
148
149#else /* defined(CONFIG_PHY_DYNAMIC_ANEG) */
150 /*
151 * Set up standard advertisement
152 */
153 u16 adv;
154
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500155 miiphy_read (devname, addr, MII_ADVERTISE, &adv);
156 adv |= (LPA_LPACK | LPA_100FULL | LPA_100HALF |
157 LPA_10FULL | LPA_10HALF);
158 miiphy_write (devname, addr, MII_ADVERTISE, adv);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200159
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500160 miiphy_read (devname, addr, MII_CTRL1000, &adv);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200161 adv |= (0x0300);
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500162 miiphy_write (devname, addr, MII_CTRL1000, adv);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200163
Larry Johnsonc3485782007-12-27 10:50:55 -0500164#endif /* defined(CONFIG_PHY_DYNAMIC_ANEG) */
165
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200166 /* Start/Restart aneg */
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500167 miiphy_read (devname, addr, MII_BMCR, &bmcr);
168 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
169 miiphy_write (devname, addr, MII_BMCR, bmcr);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200170
171 return 0;
172}
173
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200174/***********************************************************/
175/* read a phy reg and return the value with a rc */
176/***********************************************************/
Stefan Roesec3307fa2008-02-19 21:58:25 +0100177/* AMCC_TODO:
178 * Find out of the choice for the emac for MDIO is from the bridges,
179 * i.e. ZMII or RGMII as approporiate. If the bridges are not used
180 * to determine the emac for MDIO, then is the SDR0_ETH_CFG[MDIO_SEL]
181 * used? If so, then this routine below does not apply to the 460EX/GT.
182 *
183 * sr: Currently on 460EX only EMAC0 works with MDIO, so we always
184 * return EMAC0 offset here
Victor Gallardo78d78232008-09-04 23:49:36 -0700185 * vg: For 460EX/460GT if internal GPCS PHY address is specified
186 * return appropriate EMAC offset
Stefan Roesec3307fa2008-02-19 21:58:25 +0100187 */
Victor Gallardo78d78232008-09-04 23:49:36 -0700188unsigned int miiphy_getemac_offset(u8 addr)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200189{
Mike Frysingere2a53452011-10-02 10:01:27 +0000190#if defined(CONFIG_440) && \
Stefan Roesec3307fa2008-02-19 21:58:25 +0100191 !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
Mike Frysingere2a53452011-10-02 10:01:27 +0000192 !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200193 unsigned long zmii;
194 unsigned long eoffset;
195
196 /* Need to find out which mdi port we're using */
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200197 zmii = in_be32((void *)ZMII0_FER);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200198
Larry Johnsonc3485782007-12-27 10:50:55 -0500199 if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200200 /* using port 0 */
201 eoffset = 0;
Larry Johnsonc3485782007-12-27 10:50:55 -0500202
203 else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200204 /* using port 1 */
205 eoffset = 0x100;
Larry Johnsonc3485782007-12-27 10:50:55 -0500206
207 else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200208 /* using port 2 */
209 eoffset = 0x400;
Larry Johnsonc3485782007-12-27 10:50:55 -0500210
211 else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3)))
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200212 /* using port 3 */
213 eoffset = 0x600;
Larry Johnsonc3485782007-12-27 10:50:55 -0500214
215 else {
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200216 /* None of the mdi ports are enabled! */
217 /* enable port 0 */
218 zmii |= ZMII_FER_MDI << ZMII_FER_V (0);
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200219 out_be32((void *)ZMII0_FER, zmii);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200220 eoffset = 0;
221 /* need to soft reset port 0 */
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200222 zmii = in_be32((void *)EMAC0_MR0);
223 zmii |= EMAC_MR0_SRST;
224 out_be32((void *)EMAC0_MR0, zmii);
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200225 }
226
227 return (eoffset);
228#else
Stefan Roesedbbd1252007-10-05 17:10:59 +0200229
Mike Frysingere2a53452011-10-02 10:01:27 +0000230#if defined(CONFIG_405EX)
Stefan Roesedbbd1252007-10-05 17:10:59 +0200231 unsigned long rgmii;
232 int devnum = 1;
233
Stefan Roese2d834762007-10-23 14:03:17 +0200234 rgmii = in_be32((void *)RGMII_FER);
Stefan Roesedbbd1252007-10-05 17:10:59 +0200235 if (rgmii & (1 << (19 - devnum)))
236 return 0x100;
237#endif
238
Victor Gallardo78d78232008-09-04 23:49:36 -0700239#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Victor Gallardo78d78232008-09-04 23:49:36 -0700240 u32 eoffset = 0;
241
242 switch (addr) {
243#if defined(CONFIG_HAS_ETH1) && defined(CONFIG_GPCS_PHY1_ADDR)
244 case CONFIG_GPCS_PHY1_ADDR:
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200245 if (addr == EMAC_MR1_IPPA_GET(in_be32((void *)EMAC0_MR1 + 0x100)))
Victor Gallardo78d78232008-09-04 23:49:36 -0700246 eoffset = 0x100;
247 break;
248#endif
249#if defined(CONFIG_HAS_ETH2) && defined(CONFIG_GPCS_PHY2_ADDR)
250 case CONFIG_GPCS_PHY2_ADDR:
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200251 if (addr == EMAC_MR1_IPPA_GET(in_be32((void *)EMAC0_MR1 + 0x300)))
Victor Gallardo78d78232008-09-04 23:49:36 -0700252 eoffset = 0x300;
253 break;
254#endif
255#if defined(CONFIG_HAS_ETH3) && defined(CONFIG_GPCS_PHY3_ADDR)
256 case CONFIG_GPCS_PHY3_ADDR:
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200257 if (addr == EMAC_MR1_IPPA_GET(in_be32((void *)EMAC0_MR1 + 0x400)))
Victor Gallardo78d78232008-09-04 23:49:36 -0700258 eoffset = 0x400;
259 break;
260#endif
261 default:
262 eoffset = 0;
263 break;
264 }
265 return eoffset;
266#endif
267
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200268 return 0;
269#endif
270}
271
Stefan Roesec3307fa2008-02-19 21:58:25 +0100272static int emac_miiphy_wait(u32 emac_reg)
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200273{
Stefan Roesec3307fa2008-02-19 21:58:25 +0100274 u32 sta_reg;
275 int i;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200276
Stefan Roesec3307fa2008-02-19 21:58:25 +0100277 /* wait for completion */
wdenkaffae2b2002-08-17 09:36:01 +0000278 i = 0;
Stefan Roesec3307fa2008-02-19 21:58:25 +0100279 do {
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200280 sta_reg = in_be32((void *)EMAC0_STACR + emac_reg);
Stefan Roesec3307fa2008-02-19 21:58:25 +0100281 if (i++ > 5) {
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200282 debug("%s [%d]: Timeout! EMAC0_STACR=0x%0x\n", __func__,
Stefan Roesec3307fa2008-02-19 21:58:25 +0100283 __LINE__, sta_reg);
wdenkaffae2b2002-08-17 09:36:01 +0000284 return -1;
285 }
Stefan Roesec3307fa2008-02-19 21:58:25 +0100286 udelay(10);
287 } while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK);
288
289 return 0;
290}
291
292static int emac_miiphy_command(u8 addr, u8 reg, int cmd, u16 value)
293{
294 u32 emac_reg;
295 u32 sta_reg;
296
Victor Gallardo78d78232008-09-04 23:49:36 -0700297 emac_reg = miiphy_getemac_offset(addr);
Stefan Roesec3307fa2008-02-19 21:58:25 +0100298
299 /* wait for completion */
300 if (emac_miiphy_wait(emac_reg) != 0)
301 return -1;
302
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200303 sta_reg = reg; /* reg address */
Stefan Roesec3307fa2008-02-19 21:58:25 +0100304
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200305 /* set clock (50MHz) and read flags */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200306#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200307 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesec3307fa2008-02-19 21:58:25 +0100308 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200309 defined(CONFIG_405EX)
Larry Johnsonc3485782007-12-27 10:50:55 -0500310#if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */
Stefan Roesec3307fa2008-02-19 21:58:25 +0100311 sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | cmd;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200312#else
Stefan Roesec3307fa2008-02-19 21:58:25 +0100313 sta_reg |= cmd;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200314#endif
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200315#else
Stefan Roesec3307fa2008-02-19 21:58:25 +0100316 sta_reg = (sta_reg | cmd) & ~EMAC_STACR_CLK_100MHZ;
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200317#endif
318
Stefan Roesec3307fa2008-02-19 21:58:25 +0100319 /* Some boards (mainly 405EP based) define the PHY clock freqency fixed */
wdenk12f34242003-09-02 22:48:03 +0000320 sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ;
Stefan Roesec3307fa2008-02-19 21:58:25 +0100321 sta_reg = sta_reg | ((u32)addr << 5); /* Phy address */
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200322 sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */
Stefan Roesec3307fa2008-02-19 21:58:25 +0100323 if (cmd == EMAC_STACR_WRITE)
324 memcpy(&sta_reg, &value, 2); /* put in data */
325
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200326 out_be32((void *)EMAC0_STACR + emac_reg, sta_reg);
Stefan Roesec3307fa2008-02-19 21:58:25 +0100327 debug("%s [%d]: sta_reg=%08x\n", __func__, __LINE__, sta_reg);
wdenkaffae2b2002-08-17 09:36:01 +0000328
Stefan Roesec3307fa2008-02-19 21:58:25 +0100329 /* wait for completion */
330 if (emac_miiphy_wait(emac_reg) != 0)
331 return -1;
Larry Johnsonc3485782007-12-27 10:50:55 -0500332
Stefan Roesec3307fa2008-02-19 21:58:25 +0100333 debug("%s [%d]: sta_reg=%08x\n", __func__, __LINE__, sta_reg);
Larry Johnsonc3485782007-12-27 10:50:55 -0500334 if ((sta_reg & EMAC_STACR_PHYE) != 0)
wdenkaffae2b2002-08-17 09:36:01 +0000335 return -1;
wdenkaffae2b2002-08-17 09:36:01 +0000336
wdenkaffae2b2002-08-17 09:36:01 +0000337 return 0;
Stefan Roesec3307fa2008-02-19 21:58:25 +0100338}
wdenkaffae2b2002-08-17 09:36:01 +0000339
Mike Frysinger5700bb62010-07-27 18:35:08 -0400340int emac4xx_miiphy_read (const char *devname, unsigned char addr, unsigned char reg,
Stefan Roesec3307fa2008-02-19 21:58:25 +0100341 unsigned short *value)
342{
343 unsigned long sta_reg;
344 unsigned long emac_reg;
345
Victor Gallardo78d78232008-09-04 23:49:36 -0700346 emac_reg = miiphy_getemac_offset(addr);
Stefan Roesec3307fa2008-02-19 21:58:25 +0100347
348 if (emac_miiphy_command(addr, reg, EMAC_STACR_READ, 0) != 0)
349 return -1;
350
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200351 sta_reg = in_be32((void *)EMAC0_STACR + emac_reg);
Stefan Roese0b34dbb2009-09-07 10:52:24 +0200352 *value = sta_reg >> 16;
Stefan Roesec3307fa2008-02-19 21:58:25 +0100353
354 return 0;
355}
wdenkaffae2b2002-08-17 09:36:01 +0000356
wdenkaffae2b2002-08-17 09:36:01 +0000357/***********************************************************/
Stefan Roesed6c61aa2005-08-16 18:18:00 +0200358/* write a phy reg and return the value with a rc */
wdenkaffae2b2002-08-17 09:36:01 +0000359/***********************************************************/
360
Mike Frysinger5700bb62010-07-27 18:35:08 -0400361int emac4xx_miiphy_write (const char *devname, unsigned char addr, unsigned char reg,
Larry Johnsonc3485782007-12-27 10:50:55 -0500362 unsigned short value)
wdenkaffae2b2002-08-17 09:36:01 +0000363{
Stefan Roesec3307fa2008-02-19 21:58:25 +0100364 return emac_miiphy_command(addr, reg, EMAC_STACR_WRITE, value);
365}