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 | | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 30 | +-----------------------------------------------------------------------------*/ |
| 31 | |
Stefan Roese | 8b231b2 | 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 | 69710095 | 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 | 0c7ffc0 | 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 | 8b231b2 | 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 | 0c7ffc0 | 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 | aab8c49 | 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 | aab8c49 | 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 | 0c7ffc0 | 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 | 0c7ffc0 | 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 | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 76 | int phy_setup_aneg (char *devname, unsigned char addr) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 77 | { |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 78 | u16 bmcr; |
| 79 | |
| 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); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 95 | |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 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 | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 153 | miiphy_read (devname, addr, PHY_ANAR, &adv); |
Mike Nuss | 91c9b1a | 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 | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 156 | miiphy_write (devname, addr, PHY_ANAR, adv); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 157 | |
Marian Balakowicz | 49d0eee | 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 | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 162 | #endif /* defined(CONFIG_PHY_DYNAMIC_ANEG) */ |
| 163 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 164 | /* Start/Restart aneg */ |
Larry Johnson | 50325a0 | 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 | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Stefan Roese | 0c7ffc0 | 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 | 8b231b2 | 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 |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 183 | * vg: For 460EX/460GT if internal GPCS PHY address is specified |
| 184 | * return appropriate EMAC offset |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 185 | */ |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 186 | unsigned int miiphy_getemac_offset(u8 addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 187 | { |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 188 | #if (defined(CONFIG_440) && \ |
| 189 | !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \ |
| 190 | !defined(CONFIG_460EX) && !defined(CONFIG_460GT)) && \ |
| 191 | defined(CONFIG_NET_MULTI) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 192 | unsigned long zmii; |
| 193 | unsigned long eoffset; |
| 194 | |
| 195 | /* Need to find out which mdi port we're using */ |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 196 | zmii = in_be32((void *)ZMII_FER); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 197 | |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 198 | if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0))) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 199 | /* using port 0 */ |
| 200 | eoffset = 0; |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 201 | |
| 202 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1))) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 203 | /* using port 1 */ |
| 204 | eoffset = 0x100; |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 205 | |
| 206 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2))) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 207 | /* using port 2 */ |
| 208 | eoffset = 0x400; |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 209 | |
| 210 | else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3))) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 211 | /* using port 3 */ |
| 212 | eoffset = 0x600; |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 213 | |
| 214 | else { |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 215 | /* None of the mdi ports are enabled! */ |
| 216 | /* enable port 0 */ |
| 217 | zmii |= ZMII_FER_MDI << ZMII_FER_V (0); |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 218 | out_be32((void *)ZMII_FER, zmii); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 219 | eoffset = 0; |
| 220 | /* need to soft reset port 0 */ |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 221 | zmii = in_be32((void *)EMAC_M0); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 222 | zmii |= EMAC_M0_SRST; |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 223 | out_be32((void *)EMAC_M0, zmii); |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | return (eoffset); |
| 227 | #else |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 228 | |
| 229 | #if defined(CONFIG_NET_MULTI) && defined(CONFIG_405EX) |
| 230 | unsigned long rgmii; |
| 231 | int devnum = 1; |
| 232 | |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 233 | rgmii = in_be32((void *)RGMII_FER); |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 234 | if (rgmii & (1 << (19 - devnum))) |
| 235 | return 0x100; |
| 236 | #endif |
| 237 | |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 238 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 239 | u32 eoffset = 0; |
| 240 | |
| 241 | switch (addr) { |
| 242 | #if defined(CONFIG_HAS_ETH1) && defined(CONFIG_GPCS_PHY1_ADDR) |
| 243 | case CONFIG_GPCS_PHY1_ADDR: |
Stefan Roese | 234daa7 | 2008-09-05 14:09:09 +0200 | [diff] [blame] | 244 | if (addr == EMAC_M1_IPPA_GET(in_be32((void *)EMAC_M1 + 0x100))) |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 245 | eoffset = 0x100; |
| 246 | break; |
| 247 | #endif |
| 248 | #if defined(CONFIG_HAS_ETH2) && defined(CONFIG_GPCS_PHY2_ADDR) |
| 249 | case CONFIG_GPCS_PHY2_ADDR: |
Stefan Roese | 234daa7 | 2008-09-05 14:09:09 +0200 | [diff] [blame] | 250 | if (addr == EMAC_M1_IPPA_GET(in_be32((void *)EMAC_M1 + 0x300))) |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 251 | eoffset = 0x300; |
| 252 | break; |
| 253 | #endif |
| 254 | #if defined(CONFIG_HAS_ETH3) && defined(CONFIG_GPCS_PHY3_ADDR) |
| 255 | case CONFIG_GPCS_PHY3_ADDR: |
Stefan Roese | 234daa7 | 2008-09-05 14:09:09 +0200 | [diff] [blame] | 256 | if (addr == EMAC_M1_IPPA_GET(in_be32((void *)EMAC_M1 + 0x400))) |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 257 | eoffset = 0x400; |
| 258 | break; |
| 259 | #endif |
| 260 | default: |
| 261 | eoffset = 0; |
| 262 | break; |
| 263 | } |
| 264 | return eoffset; |
| 265 | #endif |
| 266 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 267 | return 0; |
| 268 | #endif |
| 269 | } |
| 270 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 271 | static int emac_miiphy_wait(u32 emac_reg) |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 272 | { |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 273 | u32 sta_reg; |
| 274 | int i; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 275 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 276 | /* wait for completion */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 277 | i = 0; |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 278 | do { |
| 279 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
| 280 | if (i++ > 5) { |
| 281 | debug("%s [%d]: Timeout! EMAC_STACR=0x%0x\n", __func__, |
| 282 | __LINE__, sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 283 | return -1; |
| 284 | } |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 285 | udelay(10); |
| 286 | } while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static int emac_miiphy_command(u8 addr, u8 reg, int cmd, u16 value) |
| 292 | { |
| 293 | u32 emac_reg; |
| 294 | u32 sta_reg; |
| 295 | |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 296 | emac_reg = miiphy_getemac_offset(addr); |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 297 | |
| 298 | /* wait for completion */ |
| 299 | if (emac_miiphy_wait(emac_reg) != 0) |
| 300 | return -1; |
| 301 | |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 302 | sta_reg = reg; /* reg address */ |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 303 | |
Wolfgang Denk | af0501a | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 304 | /* set clock (50MHz) and read flags */ |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 305 | #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 306 | defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \ |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 307 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 308 | defined(CONFIG_405EX) |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 309 | #if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */ |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 310 | sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | cmd; |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 311 | #else |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 312 | sta_reg |= cmd; |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 313 | #endif |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 314 | #else |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 315 | sta_reg = (sta_reg | cmd) & ~EMAC_STACR_CLK_100MHZ; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 316 | #endif |
| 317 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 318 | /* Some boards (mainly 405EP based) define the PHY clock freqency fixed */ |
wdenk | 232fe0b | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 319 | sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 320 | sta_reg = sta_reg | ((u32)addr << 5); /* Phy address */ |
Marian Balakowicz | 49d0eee | 2006-06-30 16:30:46 +0200 | [diff] [blame] | 321 | sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */ |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 322 | if (cmd == EMAC_STACR_WRITE) |
| 323 | memcpy(&sta_reg, &value, 2); /* put in data */ |
| 324 | |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 325 | out_be32((void *)EMAC_STACR + emac_reg, sta_reg); |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 326 | debug("%s [%d]: sta_reg=%08x\n", __func__, __LINE__, sta_reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 327 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 328 | /* wait for completion */ |
| 329 | if (emac_miiphy_wait(emac_reg) != 0) |
| 330 | return -1; |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 331 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 332 | debug("%s [%d]: sta_reg=%08x\n", __func__, __LINE__, sta_reg); |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 333 | if ((sta_reg & EMAC_STACR_PHYE) != 0) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 334 | return -1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 335 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 336 | return 0; |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 337 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 338 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 339 | int emac4xx_miiphy_read (char *devname, unsigned char addr, unsigned char reg, |
| 340 | unsigned short *value) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 341 | { |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 342 | unsigned long sta_reg; |
Stefan Roese | 0c7ffc0 | 2005-08-16 18:18:00 +0200 | [diff] [blame] | 343 | unsigned long emac_reg; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 344 | |
Victor Gallardo | 45a06ff | 2008-09-04 23:49:36 -0700 | [diff] [blame] | 345 | emac_reg = miiphy_getemac_offset(addr); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 346 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 347 | if (emac_miiphy_command(addr, reg, EMAC_STACR_READ, 0) != 0) |
| 348 | return -1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 349 | |
Stefan Roese | 69710095 | 2007-10-23 14:03:17 +0200 | [diff] [blame] | 350 | sta_reg = in_be32((void *)EMAC_STACR + emac_reg); |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 351 | *value = *(u16 *)(&sta_reg); |
Larry Johnson | 50325a0 | 2007-12-27 10:50:55 -0500 | [diff] [blame] | 352 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 353 | return 0; |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 354 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 355 | |
Stefan Roese | 8b231b2 | 2008-02-19 21:58:25 +0100 | [diff] [blame] | 356 | /***********************************************************/ |
| 357 | /* write a phy reg and return the value with a rc */ |
| 358 | /***********************************************************/ |
| 359 | |
| 360 | int emac4xx_miiphy_write (char *devname, unsigned char addr, unsigned char reg, |
| 361 | unsigned short value) |
| 362 | { |
| 363 | return emac_miiphy_command(addr, reg, EMAC_STACR_WRITE, value); |
| 364 | } |