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 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 32 | /* define DEBUG for debugging output (obviously ;-)) */ |
| 33 | #if 0 |
| 34 | #define DEBUG |
| 35 | #endif |
| 36 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 37 | #include <common.h> |
| 38 | #include <asm/processor.h> |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 39 | #include <asm/io.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 40 | #include <ppc_asm.tmpl> |
| 41 | #include <commproc.h> |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 42 | #include <ppc4xx_enet.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 43 | #include <405_mal.h> |
| 44 | #include <miiphy.h> |
| 45 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 46 | #if !defined(CONFIG_PHY_CLK_FREQ) |
| 47 | #define CONFIG_PHY_CLK_FREQ 0 |
| 48 | #endif |
| 49 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 50 | /***********************************************************/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 51 | /* Dump out to the screen PHY regs */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 52 | /***********************************************************/ |
| 53 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 54 | void miiphy_dump (char *devname, unsigned char addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 55 | { |
| 56 | unsigned long i; |
| 57 | unsigned short data; |
| 58 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 59 | for (i = 0; i < 0x1A; i++) { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 60 | if (miiphy_read (devname, addr, i, &data)) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 61 | printf ("read error for reg %lx\n", i); |
| 62 | return; |
| 63 | } |
| 64 | printf ("Phy reg %lx ==> %4x\n", i, data); |
| 65 | |
| 66 | /* jump to the next set of regs */ |
| 67 | if (i == 0x07) |
| 68 | i = 0x0f; |
| 69 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 70 | } /* end for loop */ |
| 71 | } /* end dump */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 72 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 73 | /***********************************************************/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 74 | /* (Re)start autonegotiation */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 75 | /***********************************************************/ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 76 | int phy_setup_aneg (char *devname, unsigned char addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 77 | { |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 78 | u16 bmcr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 79 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 80 | #if defined(CONFIG_PHY_DYNAMIC_ANEG) |
| 81 | /* |
| 82 | * Set up advertisement based on capablilities reported by the PHY. |
| 83 | * This should work for both copper and fiber. |
| 84 | */ |
| 85 | u16 bmsr; |
| 86 | #if defined(CONFIG_PHY_GIGE) |
| 87 | u16 exsr = 0x0000; |
| 88 | #endif |
| 89 | |
| 90 | miiphy_read (devname, addr, PHY_BMSR, &bmsr); |
| 91 | |
| 92 | #if defined(CONFIG_PHY_GIGE) |
| 93 | if (bmsr & PHY_BMSR_EXT_STAT) |
| 94 | miiphy_read (devname, addr, PHY_EXSR, &exsr); |
| 95 | |
| 96 | if (exsr & (PHY_EXSR_1000XF | PHY_EXSR_1000XH)) { |
| 97 | /* 1000BASE-X */ |
| 98 | u16 anar = 0x0000; |
| 99 | |
| 100 | if (exsr & PHY_EXSR_1000XF) |
| 101 | anar |= PHY_X_ANLPAR_FD; |
| 102 | |
| 103 | if (exsr & PHY_EXSR_1000XH) |
| 104 | anar |= PHY_X_ANLPAR_HD; |
| 105 | |
| 106 | miiphy_write (devname, addr, PHY_ANAR, anar); |
| 107 | } else |
| 108 | #endif |
| 109 | { |
| 110 | u16 anar, btcr; |
| 111 | |
| 112 | miiphy_read (devname, addr, PHY_ANAR, &anar); |
| 113 | anar &= ~(0x5000 | PHY_ANLPAR_T4 | PHY_ANLPAR_TXFD | |
| 114 | PHY_ANLPAR_TX | PHY_ANLPAR_10FD | PHY_ANLPAR_10); |
| 115 | |
| 116 | miiphy_read (devname, addr, PHY_1000BTCR, &btcr); |
| 117 | btcr &= ~(0x00FF | PHY_1000BTCR_1000FD | PHY_1000BTCR_1000HD); |
| 118 | |
| 119 | if (bmsr & PHY_BMSR_100T4) |
| 120 | anar |= PHY_ANLPAR_T4; |
| 121 | |
| 122 | if (bmsr & PHY_BMSR_100TXF) |
| 123 | anar |= PHY_ANLPAR_TXFD; |
| 124 | |
| 125 | if (bmsr & PHY_BMSR_100TXH) |
| 126 | anar |= PHY_ANLPAR_TX; |
| 127 | |
| 128 | if (bmsr & PHY_BMSR_10TF) |
| 129 | anar |= PHY_ANLPAR_10FD; |
| 130 | |
| 131 | if (bmsr & PHY_BMSR_10TH) |
| 132 | anar |= PHY_ANLPAR_10; |
| 133 | |
| 134 | miiphy_write (devname, addr, PHY_ANAR, anar); |
| 135 | |
| 136 | #if defined(CONFIG_PHY_GIGE) |
| 137 | if (exsr & PHY_EXSR_1000TF) |
| 138 | btcr |= PHY_1000BTCR_1000FD; |
| 139 | |
| 140 | if (exsr & PHY_EXSR_1000TH) |
| 141 | btcr |= PHY_1000BTCR_1000HD; |
| 142 | |
| 143 | miiphy_write (devname, addr, PHY_1000BTCR, btcr); |
| 144 | #endif |
| 145 | } |
| 146 | |
| 147 | #else /* defined(CONFIG_PHY_DYNAMIC_ANEG) */ |
| 148 | /* |
| 149 | * Set up standard advertisement |
| 150 | */ |
| 151 | u16 adv; |
| 152 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 153 | miiphy_read (devname, addr, PHY_ANAR, &adv); |
Mike Nuss | 74eb022 | 2008-03-03 15:27:05 -0500 | [diff] [blame] | 154 | adv |= (PHY_ANLPAR_ACK | PHY_ANLPAR_TXFD | PHY_ANLPAR_TX | |
| 155 | PHY_ANLPAR_10FD | PHY_ANLPAR_10); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 156 | miiphy_write (devname, addr, PHY_ANAR, adv); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 157 | |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 158 | miiphy_read (devname, addr, PHY_1000BTCR, &adv); |
| 159 | adv |= (0x0300); |
| 160 | miiphy_write (devname, addr, PHY_1000BTCR, adv); |
| 161 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 162 | #endif /* defined(CONFIG_PHY_DYNAMIC_ANEG) */ |
| 163 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 164 | /* Start/Restart aneg */ |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 165 | miiphy_read (devname, addr, PHY_BMCR, &bmcr); |
| 166 | bmcr |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG); |
| 167 | miiphy_write (devname, addr, PHY_BMCR, bmcr); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 172 | /***********************************************************/ |
| 173 | /* read a phy reg and return the value with a rc */ |
| 174 | /***********************************************************/ |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 175 | /* AMCC_TODO: |
| 176 | * Find out of the choice for the emac for MDIO is from the bridges, |
| 177 | * i.e. ZMII or RGMII as approporiate. If the bridges are not used |
| 178 | * to determine the emac for MDIO, then is the SDR0_ETH_CFG[MDIO_SEL] |
| 179 | * used? If so, then this routine below does not apply to the 460EX/GT. |
| 180 | * |
| 181 | * sr: Currently on 460EX only EMAC0 works with MDIO, so we always |
| 182 | * return EMAC0 offset here |
| 183 | */ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 184 | unsigned int miiphy_getemac_offset (void) |
| 185 | { |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 186 | #if (defined(CONFIG_440) && \ |
| 187 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
| 188 | !defined(CONFIG_460EX) && !defined(CONFIG_460GT)) && \ |
| 189 | defined(CONFIG_NET_MULTI) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 190 | unsigned long zmii; |
| 191 | unsigned long eoffset; |
| 192 | |
| 193 | /* Need to find out which mdi port we're using */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 194 | zmii = in_be32((void *)ZMII_FER); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 195 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 196 | if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 197 | /* using port 0 */ |
| 198 | eoffset = 0; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 199 | |
| 200 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 201 | /* using port 1 */ |
| 202 | eoffset = 0x100; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 203 | |
| 204 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 205 | /* using port 2 */ |
| 206 | eoffset = 0x400; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 207 | |
| 208 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3))) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 209 | /* using port 3 */ |
| 210 | eoffset = 0x600; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 211 | |
| 212 | else { |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 213 | /* None of the mdi ports are enabled! */ |
| 214 | /* enable port 0 */ |
| 215 | zmii |= ZMII_FER_MDI << ZMII_FER_V (0); |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 216 | out_be32((void *)ZMII_FER, zmii); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 217 | eoffset = 0; |
| 218 | /* need to soft reset port 0 */ |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 219 | zmii = in_be32((void *)EMAC_M0); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 220 | zmii |= EMAC_M0_SRST; |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 221 | out_be32((void *)EMAC_M0, zmii); |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | return (eoffset); |
| 225 | #else |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 226 | |
| 227 | #if defined(CONFIG_NET_MULTI) && defined(CONFIG_405EX) |
| 228 | unsigned long rgmii; |
| 229 | int devnum = 1; |
| 230 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 231 | rgmii = in_be32((void *)RGMII_FER); |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 232 | if (rgmii & (1 << (19 - devnum))) |
| 233 | return 0x100; |
| 234 | #endif |
| 235 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 236 | return 0; |
| 237 | #endif |
| 238 | } |
| 239 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 240 | static int emac_miiphy_wait(u32 emac_reg) |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 241 | { |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 242 | u32 sta_reg; |
| 243 | int i; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 244 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 245 | /* wait for completion */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 246 | i = 0; |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 247 | do { |
| 248 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
| 249 | if (i++ > 5) { |
| 250 | debug("%s [%d]: Timeout! EMAC_STACR=0x%0x\n", __func__, |
| 251 | __LINE__, sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 252 | return -1; |
| 253 | } |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 254 | udelay(10); |
| 255 | } while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int emac_miiphy_command(u8 addr, u8 reg, int cmd, u16 value) |
| 261 | { |
| 262 | u32 emac_reg; |
| 263 | u32 sta_reg; |
| 264 | |
| 265 | emac_reg = miiphy_getemac_offset(); |
| 266 | |
| 267 | /* wait for completion */ |
| 268 | if (emac_miiphy_wait(emac_reg) != 0) |
| 269 | return -1; |
| 270 | |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 271 | sta_reg = reg; /* reg address */ |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 272 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 273 | /* set clock (50Mhz) and read flags */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 274 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 275 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 276 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | dbbd125 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 277 | defined(CONFIG_405EX) |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 278 | #if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */ |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 279 | sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | cmd; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 280 | #else |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 281 | sta_reg |= cmd; |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 282 | #endif |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 283 | #else |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 284 | sta_reg = (sta_reg | cmd) & ~EMAC_STACR_CLK_100MHZ; |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 285 | #endif |
| 286 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 287 | /* Some boards (mainly 405EP based) define the PHY clock freqency fixed */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 288 | sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 289 | sta_reg = sta_reg | ((u32)addr << 5); /* Phy address */ |
Marian Balakowicz | 6c5879f | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 290 | sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */ |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 291 | if (cmd == EMAC_STACR_WRITE) |
| 292 | memcpy(&sta_reg, &value, 2); /* put in data */ |
| 293 | |
Stefan Roese | 2d83476 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 294 | out_be32((void *)EMAC_STACR + emac_reg, sta_reg); |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 295 | debug("%s [%d]: sta_reg=%08x\n", __func__, __LINE__, sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 296 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 297 | /* wait for completion */ |
| 298 | if (emac_miiphy_wait(emac_reg) != 0) |
| 299 | return -1; |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 300 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 301 | debug("%s [%d]: sta_reg=%08x\n", __func__, __LINE__, sta_reg); |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 302 | if ((sta_reg & EMAC_STACR_PHYE) != 0) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 303 | return -1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 304 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 305 | return 0; |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 306 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 307 | |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 308 | int emac4xx_miiphy_read (char *devname, unsigned char addr, unsigned char reg, |
| 309 | unsigned short *value) |
| 310 | { |
| 311 | unsigned long sta_reg; |
| 312 | unsigned long emac_reg; |
| 313 | |
| 314 | emac_reg = miiphy_getemac_offset (); |
| 315 | |
| 316 | if (emac_miiphy_command(addr, reg, EMAC_STACR_READ, 0) != 0) |
| 317 | return -1; |
| 318 | |
| 319 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
| 320 | *value = *(u16 *)(&sta_reg); |
| 321 | |
| 322 | return 0; |
| 323 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 324 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 325 | /***********************************************************/ |
Stefan Roese | d6c61aa | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 326 | /* write a phy reg and return the value with a rc */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 327 | /***********************************************************/ |
| 328 | |
Larry Johnson | c348578 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 329 | int emac4xx_miiphy_write (char *devname, unsigned char addr, unsigned char reg, |
| 330 | unsigned short value) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 331 | { |
Stefan Roese | c3307fa | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 332 | return emac_miiphy_command(addr, reg, EMAC_STACR_WRITE, value); |
| 333 | } |