wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------+ |
| 2 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 3 | | 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. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 9 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 10 | | 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. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 13 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 14 | | 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. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 17 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 18 | | COPYRIGHT I B M CORPORATION 1995 |
| 19 | | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 20 | +-----------------------------------------------------------------------------*/ |
| 21 | /*-----------------------------------------------------------------------------+ |
| 22 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 23 | | File Name: miiphy.c |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 24 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 25 | | Function: This module has utilities for accessing the MII PHY through |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 26 | | the EMAC3 macro. |
| 27 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 28 | | Author: Mark Wisner |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 29 | | |
| 30 | | Change Activity- |
| 31 | | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 32 | | Date Description of Change BY |
| 33 | | --------- --------------------- --- |
| 34 | | 05-May-99 Created MKW |
| 35 | | 01-Jul-99 Changed clock setting of sta_reg from 66Mhz to 50Mhz to |
| 36 | | better match OPB speed. Also modified delay times. JWB |
| 37 | | 29-Jul-99 Added Full duplex support MKW |
| 38 | | 24-Aug-99 Removed printf from dp83843_duplex() JWB |
| 39 | | 19-Jul-00 Ported to esd cpci405 sr |
| 40 | | 23-Dec-03 Ported from miiphy.c to 440GX Travis Sawyer TBS |
| 41 | | <travis.sawyer@sandburst.com> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 42 | | |
| 43 | +-----------------------------------------------------------------------------*/ |
| 44 | |
| 45 | #include <common.h> |
| 46 | #include <asm/processor.h> |
| 47 | #include <ppc_asm.tmpl> |
| 48 | #include <commproc.h> |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 49 | #include <ppc4xx_enet.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 50 | #include <405_mal.h> |
| 51 | #include <miiphy.h> |
| 52 | |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 53 | #undef ET_DEBUG |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 54 | /***********************************************************/ |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 55 | /* Dump out to the screen PHY regs */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 56 | /***********************************************************/ |
| 57 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 58 | void miiphy_dump (char *devname, unsigned char addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 59 | { |
| 60 | unsigned long i; |
| 61 | unsigned short data; |
| 62 | |
| 63 | |
| 64 | for (i = 0; i < 0x1A; i++) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 65 | if (miiphy_read (devname, addr, i, &data)) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 66 | printf ("read error for reg %lx\n", i); |
| 67 | return; |
| 68 | } |
| 69 | printf ("Phy reg %lx ==> %4x\n", i, data); |
| 70 | |
| 71 | /* jump to the next set of regs */ |
| 72 | if (i == 0x07) |
| 73 | i = 0x0f; |
| 74 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 75 | } /* end for loop */ |
| 76 | } /* end dump */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 77 | |
| 78 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 79 | /***********************************************************/ |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 80 | /* (Re)start autonegotiation */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 81 | /***********************************************************/ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 82 | int phy_setup_aneg (char *devname, unsigned char addr) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 83 | { |
| 84 | unsigned short ctl, adv; |
| 85 | |
| 86 | /* Setup standard advertise */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 87 | miiphy_read (devname, addr, PHY_ANAR, &adv); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 88 | adv |= (PHY_ANLPAR_ACK | PHY_ANLPAR_RF | PHY_ANLPAR_T4 | |
| 89 | PHY_ANLPAR_TXFD | PHY_ANLPAR_TX | PHY_ANLPAR_10FD | |
| 90 | PHY_ANLPAR_10); |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 91 | miiphy_write (devname, addr, PHY_ANAR, adv); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 92 | |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 93 | miiphy_read (devname, addr, PHY_1000BTCR, &adv); |
| 94 | adv |= (0x0300); |
| 95 | miiphy_write (devname, addr, PHY_1000BTCR, adv); |
| 96 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 97 | /* Start/Restart aneg */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 98 | miiphy_read (devname, addr, PHY_BMCR, &ctl); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 99 | ctl |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG); |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 100 | miiphy_write (devname, addr, PHY_BMCR, ctl); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /***********************************************************/ |
| 107 | /* read a phy reg and return the value with a rc */ |
| 108 | /***********************************************************/ |
| 109 | unsigned int miiphy_getemac_offset (void) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 110 | { |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 111 | #if (defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)) && defined(CONFIG_NET_MULTI) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 112 | unsigned long zmii; |
| 113 | unsigned long eoffset; |
| 114 | |
| 115 | /* Need to find out which mdi port we're using */ |
| 116 | zmii = in32 (ZMII_FER); |
| 117 | |
| 118 | if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0))) { |
| 119 | /* using port 0 */ |
| 120 | eoffset = 0; |
| 121 | } else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1))) { |
| 122 | /* using port 1 */ |
| 123 | eoffset = 0x100; |
| 124 | } else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2))) { |
| 125 | /* using port 2 */ |
| 126 | eoffset = 0x400; |
| 127 | } else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3))) { |
| 128 | /* using port 3 */ |
| 129 | eoffset = 0x600; |
| 130 | } else { |
| 131 | /* None of the mdi ports are enabled! */ |
| 132 | /* enable port 0 */ |
| 133 | zmii |= ZMII_FER_MDI << ZMII_FER_V (0); |
| 134 | out32 (ZMII_FER, zmii); |
| 135 | eoffset = 0; |
| 136 | /* need to soft reset port 0 */ |
| 137 | zmii = in32 (EMAC_M0); |
| 138 | zmii |= EMAC_M0_SRST; |
| 139 | out32 (EMAC_M0, zmii); |
| 140 | } |
| 141 | |
| 142 | return (eoffset); |
| 143 | #else |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 144 | |
| 145 | #if defined(CONFIG_NET_MULTI) && defined(CONFIG_405EX) |
| 146 | unsigned long rgmii; |
| 147 | int devnum = 1; |
| 148 | |
| 149 | rgmii = in32(RGMII_FER); |
| 150 | if (rgmii & (1 << (19 - devnum))) |
| 151 | return 0x100; |
| 152 | #endif |
| 153 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 154 | return 0; |
| 155 | #endif |
| 156 | } |
| 157 | |
| 158 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 159 | int emac4xx_miiphy_read (char *devname, unsigned char addr, |
| 160 | unsigned char reg, unsigned short *value) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 161 | { |
| 162 | unsigned long sta_reg; /* STA scratch area */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 163 | unsigned long i; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 164 | unsigned long emac_reg; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 165 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 166 | |
| 167 | emac_reg = miiphy_getemac_offset (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 168 | /* see if it is ready for 1000 nsec */ |
| 169 | i = 0; |
| 170 | |
| 171 | /* see if it is ready for sec */ |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 172 | while ((in32 (EMAC_STACR + emac_reg) & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 173 | udelay (7); |
| 174 | if (i > 5) { |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 175 | #ifdef ET_DEBUG |
| 176 | sta_reg = in32 (EMAC_STACR + emac_reg); |
| 177 | printf ("read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 178 | printf ("read err 1\n"); |
stroese | 86bb6fc | 2003-12-09 14:57:03 +0000 | [diff] [blame] | 179 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 180 | return -1; |
| 181 | } |
| 182 | i++; |
| 183 | } |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 184 | sta_reg = reg; /* reg address */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 185 | /* set clock (50Mhz) and read flags */ |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 186 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 187 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 188 | defined(CONFIG_405EX) |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 189 | #if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */ |
| 190 | sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_READ; |
| 191 | #else |
| 192 | sta_reg |= EMAC_STACR_READ; |
| 193 | #endif |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 194 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 195 | sta_reg = (sta_reg | EMAC_STACR_READ) & ~EMAC_STACR_CLK_100MHZ; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 196 | #endif |
| 197 | |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 198 | #if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \ |
| 199 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 200 | !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \ |
| 201 | !defined(CONFIG_405EX) |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 202 | sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; |
wdenk | 19cbaf4 | 2003-09-02 23:08:13 +0000 | [diff] [blame] | 203 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 204 | sta_reg = sta_reg | (addr << 5); /* Phy address */ |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 205 | sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */ |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 206 | out32 (EMAC_STACR + emac_reg, sta_reg); |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 207 | #ifdef ET_DEBUG |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 208 | printf ("a2: write: EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 209 | #endif |
| 210 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 211 | sta_reg = in32 (EMAC_STACR + emac_reg); |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 212 | #ifdef ET_DEBUG |
| 213 | printf ("a21: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 214 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 215 | i = 0; |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 216 | while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 217 | udelay (7); |
| 218 | if (i > 5) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 219 | return -1; |
| 220 | } |
| 221 | i++; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 222 | sta_reg = in32 (EMAC_STACR + emac_reg); |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 223 | #ifdef ET_DEBUG |
| 224 | printf ("a22: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 225 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 226 | } |
| 227 | if ((sta_reg & EMAC_STACR_PHYE) != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 228 | return -1; |
| 229 | } |
| 230 | |
| 231 | *value = *(short *) (&sta_reg); |
| 232 | return 0; |
| 233 | |
| 234 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 235 | } /* phy_read */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 236 | |
| 237 | |
| 238 | /***********************************************************/ |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 239 | /* write a phy reg and return the value with a rc */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 240 | /***********************************************************/ |
| 241 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 242 | int emac4xx_miiphy_write (char *devname, unsigned char addr, |
| 243 | unsigned char reg, unsigned short value) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 244 | { |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 245 | unsigned long sta_reg; /* STA scratch area */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 246 | unsigned long i; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 247 | unsigned long emac_reg; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 248 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 249 | emac_reg = miiphy_getemac_offset (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 250 | /* see if it is ready for 1000 nsec */ |
| 251 | i = 0; |
| 252 | |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 253 | while ((in32 (EMAC_STACR + emac_reg) & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 254 | if (i > 5) |
| 255 | return -1; |
| 256 | udelay (7); |
| 257 | i++; |
| 258 | } |
| 259 | sta_reg = 0; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 260 | sta_reg = reg; /* reg address */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 261 | /* set clock (50Mhz) and read flags */ |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 262 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 263 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 264 | defined(CONFIG_405EX) |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 265 | #if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */ |
| 266 | sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_WRITE; |
| 267 | #else |
| 268 | sta_reg |= EMAC_STACR_WRITE; |
| 269 | #endif |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 270 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 271 | sta_reg = (sta_reg | EMAC_STACR_WRITE) & ~EMAC_STACR_CLK_100MHZ; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 272 | #endif |
| 273 | |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 274 | #if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \ |
| 275 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 276 | !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \ |
| 277 | !defined(CONFIG_405EX) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 278 | sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; /* Set clock frequency (PLB freq. dependend) */ |
wdenk | 19cbaf4 | 2003-09-02 23:08:13 +0000 | [diff] [blame] | 279 | #endif |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 280 | sta_reg = sta_reg | ((unsigned long) addr << 5);/* Phy address */ |
| 281 | sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 282 | memcpy (&sta_reg, &value, 2); /* put in data */ |
| 283 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 284 | out32 (EMAC_STACR + emac_reg, sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 285 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 286 | /* wait for completion */ |
| 287 | i = 0; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 288 | sta_reg = in32 (EMAC_STACR + emac_reg); |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 289 | #ifdef ET_DEBUG |
| 290 | printf ("a31: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 291 | #endif |
| 292 | while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 293 | udelay (7); |
| 294 | if (i > 5) |
| 295 | return -1; |
| 296 | i++; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 297 | sta_reg = in32 (EMAC_STACR + emac_reg); |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 298 | #ifdef ET_DEBUG |
| 299 | printf ("a32: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 300 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | if ((sta_reg & EMAC_STACR_PHYE) != 0) |
| 304 | return -1; |
| 305 | return 0; |
| 306 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 307 | } /* phy_write */ |