wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------+ |
| 2 | | |
Stefan Roese | d6c61aa | 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 | d6c61aa | 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 | d6c61aa | 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 | d6c61aa | 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 | d6c61aa | 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 | d6c61aa | 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 | d6c61aa | 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 | | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 30 | +-----------------------------------------------------------------------------*/ |
| 31 | |
| 32 | #include <common.h> |
| 33 | #include <asm/processor.h> |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 34 | #include <asm/io.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 35 | #include <ppc_asm.tmpl> |
| 36 | #include <commproc.h> |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 37 | #include <ppc4xx_enet.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 38 | #include <405_mal.h> |
| 39 | #include <miiphy.h> |
| 40 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 41 | #undef ET_DEBUG |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 42 | /***********************************************************/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 43 | /* Dump out to the screen PHY regs */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 44 | /***********************************************************/ |
| 45 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 46 | void miiphy_dump (char *devname, unsigned char addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 47 | { |
| 48 | unsigned long i; |
| 49 | unsigned short data; |
| 50 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 51 | for (i = 0; i < 0x1A; i++) { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 52 | if (miiphy_read (devname, addr, i, &data)) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 53 | 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 Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 62 | } /* end for loop */ |
| 63 | } /* end dump */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 64 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 65 | /***********************************************************/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 66 | /* (Re)start autonegotiation */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 67 | /***********************************************************/ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 68 | int phy_setup_aneg (char *devname, unsigned char addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 69 | { |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 70 | u16 bmcr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 71 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 72 | #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 Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 145 | miiphy_read (devname, addr, PHY_ANAR, &adv); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 146 | 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 Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 149 | miiphy_write (devname, addr, PHY_ANAR, adv); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 150 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 151 | miiphy_read (devname, addr, PHY_1000BTCR, &adv); |
| 152 | adv |= (0x0300); |
| 153 | miiphy_write (devname, addr, PHY_1000BTCR, adv); |
| 154 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 155 | #endif /* defined(CONFIG_PHY_DYNAMIC_ANEG) */ |
| 156 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 157 | /* Start/Restart aneg */ |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 158 | 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 Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 165 | /***********************************************************/ |
| 166 | /* read a phy reg and return the value with a rc */ |
| 167 | /***********************************************************/ |
| 168 | unsigned int miiphy_getemac_offset (void) |
| 169 | { |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 170 | #if (defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)) && defined(CONFIG_NET_MULTI) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 171 | unsigned long zmii; |
| 172 | unsigned long eoffset; |
| 173 | |
| 174 | /* Need to find out which mdi port we're using */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 175 | zmii = in_be32((void *)ZMII_FER); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 176 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 177 | if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 178 | /* using port 0 */ |
| 179 | eoffset = 0; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 180 | |
| 181 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 182 | /* using port 1 */ |
| 183 | eoffset = 0x100; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 184 | |
| 185 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 186 | /* using port 2 */ |
| 187 | eoffset = 0x400; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 188 | |
| 189 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 190 | /* using port 3 */ |
| 191 | eoffset = 0x600; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 192 | |
| 193 | else { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 194 | /* None of the mdi ports are enabled! */ |
| 195 | /* enable port 0 */ |
| 196 | zmii |= ZMII_FER_MDI << ZMII_FER_V (0); |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 197 | out_be32((void *)ZMII_FER, zmii); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 198 | eoffset = 0; |
| 199 | /* need to soft reset port 0 */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 200 | zmii = in_be32((void *)EMAC_M0); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 201 | zmii |= EMAC_M0_SRST; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 202 | out_be32((void *)EMAC_M0, zmii); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | return (eoffset); |
| 206 | #else |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 207 | |
| 208 | #if defined(CONFIG_NET_MULTI) && defined(CONFIG_405EX) |
| 209 | unsigned long rgmii; |
| 210 | int devnum = 1; |
| 211 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 212 | rgmii = in_be32((void *)RGMII_FER); |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 213 | if (rgmii & (1 << (19 - devnum))) |
| 214 | return 0x100; |
| 215 | #endif |
| 216 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 217 | return 0; |
| 218 | #endif |
| 219 | } |
| 220 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 221 | int emac4xx_miiphy_read (char *devname, unsigned char addr, unsigned char reg, |
| 222 | unsigned short *value) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 223 | { |
| 224 | unsigned long sta_reg; /* STA scratch area */ |
| 225 | unsigned long i; |
| 226 | unsigned long emac_reg; |
| 227 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 228 | emac_reg = miiphy_getemac_offset (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 229 | /* see if it is ready for 1000 nsec */ |
| 230 | i = 0; |
| 231 | |
| 232 | /* see if it is ready for sec */ |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 233 | while ((in_be32((void *)EMAC_STACR + emac_reg) & EMAC_STACR_OC) == |
| 234 | EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 235 | udelay (7); |
| 236 | if (i > 5) { |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 237 | #ifdef ET_DEBUG |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 238 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 239 | printf ("read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 240 | printf ("read err 1\n"); |
stroese | 38a9519 | 2003-12-09 14:57:03 +0000 | [diff] [blame] | 241 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 242 | return -1; |
| 243 | } |
| 244 | i++; |
| 245 | } |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 246 | sta_reg = reg; /* reg address */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 247 | /* set clock (50Mhz) and read flags */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 248 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 249 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 250 | defined(CONFIG_405EX) |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 251 | #if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */ |
| 252 | sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_READ; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 253 | #else |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 254 | sta_reg |= EMAC_STACR_READ; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 255 | #endif |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 256 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 257 | sta_reg = (sta_reg | EMAC_STACR_READ) & ~EMAC_STACR_CLK_100MHZ; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 258 | #endif |
| 259 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 260 | #if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \ |
| 261 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 262 | !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \ |
| 263 | !defined(CONFIG_405EX) |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 264 | sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; |
wdenk | 093ae27 | 2003-09-02 23:08:13 +0000 | [diff] [blame] | 265 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 266 | sta_reg = sta_reg | (addr << 5); /* Phy address */ |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 267 | sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 268 | out_be32((void *)EMAC_STACR + emac_reg, sta_reg); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 269 | #ifdef ET_DEBUG |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 270 | printf ("a2: write: EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 271 | #endif |
| 272 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 273 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 274 | #ifdef ET_DEBUG |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 275 | printf ("a21: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 276 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 277 | i = 0; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 278 | while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 279 | udelay (7); |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 280 | if (i > 5) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 281 | return -1; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 282 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 283 | i++; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 284 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 285 | #ifdef ET_DEBUG |
| 286 | printf ("a22: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 287 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 288 | } |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 289 | if ((sta_reg & EMAC_STACR_PHYE) != 0) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 290 | return -1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 291 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 292 | *value = *(short *)(&sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 293 | return 0; |
| 294 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 295 | } /* phy_read */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 296 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 297 | /***********************************************************/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 298 | /* write a phy reg and return the value with a rc */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 299 | /***********************************************************/ |
| 300 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 301 | int emac4xx_miiphy_write (char *devname, unsigned char addr, unsigned char reg, |
| 302 | unsigned short value) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 303 | { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 304 | unsigned long sta_reg; /* STA scratch area */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 305 | unsigned long i; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 306 | unsigned long emac_reg; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 307 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 308 | emac_reg = miiphy_getemac_offset (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 309 | /* see if it is ready for 1000 nsec */ |
| 310 | i = 0; |
| 311 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 312 | while ((in_be32((void *)EMAC_STACR + emac_reg) & EMAC_STACR_OC) == |
| 313 | EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 314 | if (i > 5) |
| 315 | return -1; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 316 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 317 | udelay (7); |
| 318 | i++; |
| 319 | } |
| 320 | sta_reg = 0; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 321 | sta_reg = reg; /* reg address */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 322 | /* set clock (50Mhz) and read flags */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 323 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 324 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
| 325 | defined(CONFIG_405EX) |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 326 | #if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */ |
| 327 | sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_WRITE; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 328 | #else |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 329 | sta_reg |= EMAC_STACR_WRITE; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 330 | #endif |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 331 | #else |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 332 | sta_reg = (sta_reg | EMAC_STACR_WRITE) & ~EMAC_STACR_CLK_100MHZ; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 333 | #endif |
| 334 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 335 | #if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \ |
| 336 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 337 | !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \ |
| 338 | !defined(CONFIG_405EX) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 339 | sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; /* Set clock frequency (PLB freq. dependend) */ |
wdenk | 093ae27 | 2003-09-02 23:08:13 +0000 | [diff] [blame] | 340 | #endif |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 341 | sta_reg = sta_reg | ((unsigned long)addr << 5); /* Phy address */ |
| 342 | sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 343 | memcpy (&sta_reg, &value, 2); /* put in data */ |
| 344 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 345 | out_be32((void *)EMAC_STACR + emac_reg, sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 346 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 347 | /* wait for completion */ |
| 348 | i = 0; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 349 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 350 | #ifdef ET_DEBUG |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 351 | printf ("a31: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 352 | #endif |
| 353 | while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 354 | udelay (7); |
| 355 | if (i > 5) |
| 356 | return -1; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 357 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 358 | i++; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 359 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 360 | #ifdef ET_DEBUG |
| 361 | printf ("a32: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */ |
| 362 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | if ((sta_reg & EMAC_STACR_PHYE) != 0) |
| 366 | return -1; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 367 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 368 | return 0; |
| 369 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 370 | } /* phy_write */ |