Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2009 Ilya Yanok, Emcraft Systems Ltd <yanok@emcraft.com> |
| 3 | * (C) Copyright 2008,2009 Eric Jarrige <eric.jarrige@armadeus.org> |
| 4 | * (C) Copyright 2008 Armadeus Systems nc |
| 5 | * (C) Copyright 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de> |
| 6 | * (C) Copyright 2007 Pengutronix, Juergen Beisert <j.beisert@pengutronix.de> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <malloc.h> |
| 26 | #include <net.h> |
| 27 | #include <miiphy.h> |
| 28 | #include "fec_mxc.h" |
| 29 | |
| 30 | #include <asm/arch/clock.h> |
| 31 | #include <asm/arch/imx-regs.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/errno.h> |
| 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
| 37 | #ifndef CONFIG_MII |
| 38 | #error "CONFIG_MII has to be defined!" |
| 39 | #endif |
| 40 | |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 41 | #ifndef CONFIG_FEC_XCV_TYPE |
| 42 | #define CONFIG_FEC_XCV_TYPE MII100 |
Marek Vasut | 392b850 | 2011-09-11 18:05:33 +0000 | [diff] [blame] | 43 | #endif |
| 44 | |
Marek Vasut | be7e87e | 2011-11-08 23:18:10 +0000 | [diff] [blame] | 45 | /* |
| 46 | * The i.MX28 operates with packets in big endian. We need to swap them before |
| 47 | * sending and after receiving. |
| 48 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 49 | #ifdef CONFIG_MX28 |
| 50 | #define CONFIG_FEC_MXC_SWAP_PACKET |
| 51 | #endif |
| 52 | |
| 53 | #define RXDESC_PER_CACHELINE (ARCH_DMA_MINALIGN/sizeof(struct fec_bd)) |
| 54 | |
| 55 | /* Check various alignment issues at compile time */ |
| 56 | #if ((ARCH_DMA_MINALIGN < 16) || (ARCH_DMA_MINALIGN % 16 != 0)) |
| 57 | #error "ARCH_DMA_MINALIGN must be multiple of 16!" |
| 58 | #endif |
| 59 | |
| 60 | #if ((PKTALIGN < ARCH_DMA_MINALIGN) || \ |
| 61 | (PKTALIGN % ARCH_DMA_MINALIGN != 0)) |
| 62 | #error "PKTALIGN must be multiple of ARCH_DMA_MINALIGN!" |
Marek Vasut | be7e87e | 2011-11-08 23:18:10 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 65 | #undef DEBUG |
| 66 | |
| 67 | struct nbuf { |
| 68 | uint8_t data[1500]; /**< actual data */ |
| 69 | int length; /**< actual length */ |
| 70 | int used; /**< buffer in use or not */ |
| 71 | uint8_t head[16]; /**< MAC header(6 + 6 + 2) + 2(aligned) */ |
| 72 | }; |
| 73 | |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 74 | #ifdef CONFIG_FEC_MXC_SWAP_PACKET |
Marek Vasut | be7e87e | 2011-11-08 23:18:10 +0000 | [diff] [blame] | 75 | static void swap_packet(uint32_t *packet, int length) |
| 76 | { |
| 77 | int i; |
| 78 | |
| 79 | for (i = 0; i < DIV_ROUND_UP(length, 4); i++) |
| 80 | packet[i] = __swab32(packet[i]); |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | /* |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 85 | * MII-interface related functions |
| 86 | */ |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 87 | static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyAddr, |
| 88 | uint8_t regAddr) |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 89 | { |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 90 | uint32_t reg; /* convenient holder for the PHY register */ |
| 91 | uint32_t phy; /* convenient holder for the PHY */ |
| 92 | uint32_t start; |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 93 | int val; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * reading from any PHY's register is done by properly |
| 97 | * programming the FEC's MII data register. |
| 98 | */ |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 99 | writel(FEC_IEVENT_MII, ð->ievent); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 100 | reg = regAddr << FEC_MII_DATA_RA_SHIFT; |
| 101 | phy = phyAddr << FEC_MII_DATA_PA_SHIFT; |
| 102 | |
| 103 | writel(FEC_MII_DATA_ST | FEC_MII_DATA_OP_RD | FEC_MII_DATA_TA | |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 104 | phy | reg, ð->mii_data); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * wait for the related interrupt |
| 108 | */ |
Graeme Russ | a60d1e5 | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 109 | start = get_timer(0); |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 110 | while (!(readl(ð->ievent) & FEC_IEVENT_MII)) { |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 111 | if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) { |
| 112 | printf("Read MDIO failed...\n"); |
| 113 | return -1; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * clear mii interrupt bit |
| 119 | */ |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 120 | writel(FEC_IEVENT_MII, ð->ievent); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * it's now safe to read the PHY's register |
| 124 | */ |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 125 | val = (unsigned short)readl(ð->mii_data); |
| 126 | debug("%s: phy: %02x reg:%02x val:%#x\n", __func__, phyAddr, |
| 127 | regAddr, val); |
| 128 | return val; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 129 | } |
| 130 | |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 131 | static void fec_mii_setspeed(struct fec_priv *fec) |
| 132 | { |
| 133 | /* |
| 134 | * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock |
| 135 | * and do not drop the Preamble. |
| 136 | */ |
| 137 | writel((((imx_get_fecclk() / 1000000) + 2) / 5) << 1, |
| 138 | &fec->eth->mii_speed); |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 139 | debug("%s: mii_speed %08x\n", __func__, readl(&fec->eth->mii_speed)); |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 140 | } |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 141 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 142 | static int fec_mdio_write(struct ethernet_regs *eth, uint8_t phyAddr, |
| 143 | uint8_t regAddr, uint16_t data) |
| 144 | { |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 145 | uint32_t reg; /* convenient holder for the PHY register */ |
| 146 | uint32_t phy; /* convenient holder for the PHY */ |
| 147 | uint32_t start; |
| 148 | |
| 149 | reg = regAddr << FEC_MII_DATA_RA_SHIFT; |
| 150 | phy = phyAddr << FEC_MII_DATA_PA_SHIFT; |
| 151 | |
| 152 | writel(FEC_MII_DATA_ST | FEC_MII_DATA_OP_WR | |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 153 | FEC_MII_DATA_TA | phy | reg | data, ð->mii_data); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 154 | |
| 155 | /* |
| 156 | * wait for the MII interrupt |
| 157 | */ |
Graeme Russ | a60d1e5 | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 158 | start = get_timer(0); |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 159 | while (!(readl(ð->ievent) & FEC_IEVENT_MII)) { |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 160 | if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) { |
| 161 | printf("Write MDIO failed...\n"); |
| 162 | return -1; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * clear MII interrupt bit |
| 168 | */ |
Marek Vasut | d133b88 | 2011-09-11 18:05:34 +0000 | [diff] [blame] | 169 | writel(FEC_IEVENT_MII, ð->ievent); |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 170 | debug("%s: phy: %02x reg:%02x val:%#x\n", __func__, phyAddr, |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 171 | regAddr, data); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 176 | int fec_phy_read(struct mii_dev *bus, int phyAddr, int dev_addr, int regAddr) |
| 177 | { |
| 178 | return fec_mdio_read(bus->priv, phyAddr, regAddr); |
| 179 | } |
| 180 | |
| 181 | int fec_phy_write(struct mii_dev *bus, int phyAddr, int dev_addr, int regAddr, |
| 182 | u16 data) |
| 183 | { |
| 184 | return fec_mdio_write(bus->priv, phyAddr, regAddr, data); |
| 185 | } |
| 186 | |
| 187 | #ifndef CONFIG_PHYLIB |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 188 | static int miiphy_restart_aneg(struct eth_device *dev) |
| 189 | { |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 190 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 191 | struct ethernet_regs *eth = fec->bus->priv; |
Marek Vasut | 2e5f442 | 2011-09-11 18:05:36 +0000 | [diff] [blame] | 192 | int ret = 0; |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 193 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 194 | /* |
| 195 | * Wake up from sleep if necessary |
| 196 | * Reset PHY, then delay 300ns |
| 197 | */ |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 198 | #ifdef CONFIG_MX27 |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 199 | fec_mdio_write(eth, fec->phy_id, MII_DCOUNTER, 0x00FF); |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 200 | #endif |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 201 | fec_mdio_write(eth, fec->phy_id, MII_BMCR, BMCR_RESET); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 202 | udelay(1000); |
| 203 | |
| 204 | /* |
| 205 | * Set the auto-negotiation advertisement register bits |
| 206 | */ |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 207 | fec_mdio_write(eth, fec->phy_id, MII_ADVERTISE, |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 208 | LPA_100FULL | LPA_100HALF | LPA_10FULL | |
| 209 | LPA_10HALF | PHY_ANLPAR_PSB_802_3); |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 210 | fec_mdio_write(eth, fec->phy_id, MII_BMCR, |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 211 | BMCR_ANENABLE | BMCR_ANRESTART); |
Marek Vasut | 2e5f442 | 2011-09-11 18:05:36 +0000 | [diff] [blame] | 212 | |
| 213 | if (fec->mii_postcall) |
| 214 | ret = fec->mii_postcall(fec->phy_id); |
| 215 | |
| 216 | return ret; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static int miiphy_wait_aneg(struct eth_device *dev) |
| 220 | { |
| 221 | uint32_t start; |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 222 | int status; |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 223 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 224 | struct ethernet_regs *eth = fec->bus->priv; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * Wait for AN completion |
| 228 | */ |
Graeme Russ | a60d1e5 | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 229 | start = get_timer(0); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 230 | do { |
| 231 | if (get_timer(start) > (CONFIG_SYS_HZ * 5)) { |
| 232 | printf("%s: Autonegotiation timeout\n", dev->name); |
| 233 | return -1; |
| 234 | } |
| 235 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 236 | status = fec_mdio_read(eth, fec->phy_id, MII_BMSR); |
| 237 | if (status < 0) { |
| 238 | printf("%s: Autonegotiation failed. status: %d\n", |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 239 | dev->name, status); |
| 240 | return -1; |
| 241 | } |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 242 | } while (!(status & BMSR_LSTATUS)); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 246 | #endif |
| 247 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 248 | static int fec_rx_task_enable(struct fec_priv *fec) |
| 249 | { |
| 250 | writel(1 << 24, &fec->eth->r_des_active); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static int fec_rx_task_disable(struct fec_priv *fec) |
| 255 | { |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | static int fec_tx_task_enable(struct fec_priv *fec) |
| 260 | { |
| 261 | writel(1 << 24, &fec->eth->x_des_active); |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static int fec_tx_task_disable(struct fec_priv *fec) |
| 266 | { |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Initialize receive task's buffer descriptors |
| 272 | * @param[in] fec all we know about the device yet |
| 273 | * @param[in] count receive buffer count to be allocated |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 274 | * @param[in] dsize desired size of each receive buffer |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 275 | * @return 0 on success |
| 276 | * |
| 277 | * For this task we need additional memory for the data buffers. And each |
| 278 | * data buffer requires some alignment. Thy must be aligned to a specific |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 279 | * boundary each. |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 280 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 281 | static int fec_rbd_init(struct fec_priv *fec, int count, int dsize) |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 282 | { |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 283 | uint32_t size; |
| 284 | int i; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 285 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 286 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 287 | * Allocate memory for the buffers. This allocation respects the |
| 288 | * alignment |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 289 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 290 | size = roundup(dsize, ARCH_DMA_MINALIGN); |
| 291 | for (i = 0; i < count; i++) { |
| 292 | uint32_t data_ptr = readl(&fec->rbd_base[i].data_pointer); |
| 293 | if (data_ptr == 0) { |
| 294 | uint8_t *data = memalign(ARCH_DMA_MINALIGN, |
| 295 | size); |
| 296 | if (!data) { |
| 297 | printf("%s: error allocating rxbuf %d\n", |
| 298 | __func__, i); |
| 299 | goto err; |
| 300 | } |
| 301 | writel((uint32_t)data, &fec->rbd_base[i].data_pointer); |
| 302 | } /* needs allocation */ |
| 303 | writew(FEC_RBD_EMPTY, &fec->rbd_base[i].status); |
| 304 | writew(0, &fec->rbd_base[i].data_length); |
| 305 | } |
| 306 | |
| 307 | /* Mark the last RBD to close the ring. */ |
| 308 | writew(FEC_RBD_WRAP | FEC_RBD_EMPTY, &fec->rbd_base[i - 1].status); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 309 | fec->rbd_index = 0; |
| 310 | |
| 311 | return 0; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 312 | |
| 313 | err: |
| 314 | for (; i >= 0; i--) { |
| 315 | uint32_t data_ptr = readl(&fec->rbd_base[i].data_pointer); |
| 316 | free((void *)data_ptr); |
| 317 | } |
| 318 | |
| 319 | return -ENOMEM; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Initialize transmit task's buffer descriptors |
| 324 | * @param[in] fec all we know about the device yet |
| 325 | * |
| 326 | * Transmit buffers are created externally. We only have to init the BDs here.\n |
| 327 | * Note: There is a race condition in the hardware. When only one BD is in |
| 328 | * use it must be marked with the WRAP bit to use it for every transmitt. |
| 329 | * This bit in combination with the READY bit results into double transmit |
| 330 | * of each data buffer. It seems the state machine checks READY earlier then |
| 331 | * resetting it after the first transfer. |
| 332 | * Using two BDs solves this issue. |
| 333 | */ |
| 334 | static void fec_tbd_init(struct fec_priv *fec) |
| 335 | { |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 336 | unsigned addr = (unsigned)fec->tbd_base; |
| 337 | unsigned size = roundup(2 * sizeof(struct fec_bd), |
| 338 | ARCH_DMA_MINALIGN); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 339 | writew(0x0000, &fec->tbd_base[0].status); |
| 340 | writew(FEC_TBD_WRAP, &fec->tbd_base[1].status); |
| 341 | fec->tbd_index = 0; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 342 | flush_dcache_range(addr, addr+size); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Mark the given read buffer descriptor as free |
| 347 | * @param[in] last 1 if this is the last buffer descriptor in the chain, else 0 |
| 348 | * @param[in] pRbd buffer descriptor to mark free again |
| 349 | */ |
| 350 | static void fec_rbd_clean(int last, struct fec_bd *pRbd) |
| 351 | { |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 352 | unsigned short flags = FEC_RBD_EMPTY; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 353 | if (last) |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 354 | flags |= FEC_RBD_WRAP; |
| 355 | writew(flags, &pRbd->status); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 356 | writew(0, &pRbd->data_length); |
| 357 | } |
| 358 | |
Fabio Estevam | be252b6 | 2011-12-20 05:46:31 +0000 | [diff] [blame] | 359 | static int fec_get_hwaddr(struct eth_device *dev, int dev_id, |
| 360 | unsigned char *mac) |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 361 | { |
Fabio Estevam | be252b6 | 2011-12-20 05:46:31 +0000 | [diff] [blame] | 362 | imx_get_mac_from_fuse(dev_id, mac); |
Eric Jarrige | 2e236bf | 2010-04-16 00:03:19 +0200 | [diff] [blame] | 363 | return !is_valid_ether_addr(mac); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 364 | } |
| 365 | |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 366 | static int fec_set_hwaddr(struct eth_device *dev) |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 367 | { |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 368 | uchar *mac = dev->enetaddr; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 369 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
| 370 | |
| 371 | writel(0, &fec->eth->iaddr1); |
| 372 | writel(0, &fec->eth->iaddr2); |
| 373 | writel(0, &fec->eth->gaddr1); |
| 374 | writel(0, &fec->eth->gaddr2); |
| 375 | |
| 376 | /* |
| 377 | * Set physical address |
| 378 | */ |
| 379 | writel((mac[0] << 24) + (mac[1] << 16) + (mac[2] << 8) + mac[3], |
| 380 | &fec->eth->paddr1); |
| 381 | writel((mac[4] << 24) + (mac[5] << 16) + 0x8808, &fec->eth->paddr2); |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 386 | static void fec_eth_phy_config(struct eth_device *dev) |
| 387 | { |
| 388 | #ifdef CONFIG_PHYLIB |
| 389 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
| 390 | struct phy_device *phydev; |
| 391 | |
| 392 | phydev = phy_connect(fec->bus, fec->phy_id, dev, |
| 393 | PHY_INTERFACE_MODE_RGMII); |
| 394 | if (phydev) { |
| 395 | fec->phydev = phydev; |
| 396 | phy_config(phydev); |
| 397 | } |
| 398 | #endif |
| 399 | } |
| 400 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 401 | /** |
| 402 | * Start the FEC engine |
| 403 | * @param[in] dev Our device to handle |
| 404 | */ |
| 405 | static int fec_open(struct eth_device *edev) |
| 406 | { |
| 407 | struct fec_priv *fec = (struct fec_priv *)edev->priv; |
Troy Kisky | 28774cb | 2012-02-07 14:08:46 +0000 | [diff] [blame] | 408 | int speed; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 409 | uint32_t addr, size; |
| 410 | int i; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 411 | |
| 412 | debug("fec_open: fec_open(dev)\n"); |
| 413 | /* full-duplex, heartbeat disabled */ |
| 414 | writel(1 << 2, &fec->eth->x_cntrl); |
| 415 | fec->rbd_index = 0; |
| 416 | |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 417 | /* Invalidate all descriptors */ |
| 418 | for (i = 0; i < FEC_RBD_NUM - 1; i++) |
| 419 | fec_rbd_clean(0, &fec->rbd_base[i]); |
| 420 | fec_rbd_clean(1, &fec->rbd_base[i]); |
| 421 | |
| 422 | /* Flush the descriptors into RAM */ |
| 423 | size = roundup(FEC_RBD_NUM * sizeof(struct fec_bd), |
| 424 | ARCH_DMA_MINALIGN); |
| 425 | addr = (uint32_t)fec->rbd_base; |
| 426 | flush_dcache_range(addr, addr + size); |
| 427 | |
Troy Kisky | 28774cb | 2012-02-07 14:08:46 +0000 | [diff] [blame] | 428 | #ifdef FEC_QUIRK_ENET_MAC |
Jason Liu | 2ef2b95 | 2011-12-16 05:17:07 +0000 | [diff] [blame] | 429 | /* Enable ENET HW endian SWAP */ |
| 430 | writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_DBSWAP, |
| 431 | &fec->eth->ecntrl); |
| 432 | /* Enable ENET store and forward mode */ |
| 433 | writel(readl(&fec->eth->x_wmrk) | FEC_X_WMRK_STRFWD, |
| 434 | &fec->eth->x_wmrk); |
| 435 | #endif |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 436 | /* |
| 437 | * Enable FEC-Lite controller |
| 438 | */ |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 439 | writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_ETHER_EN, |
| 440 | &fec->eth->ecntrl); |
Liu Hui-R64343 | 9691245 | 2011-01-03 22:27:36 +0000 | [diff] [blame] | 441 | #if defined(CONFIG_MX25) || defined(CONFIG_MX53) |
John Rigby | 740d6ae | 2010-01-25 23:12:57 -0700 | [diff] [blame] | 442 | udelay(100); |
| 443 | /* |
| 444 | * setup the MII gasket for RMII mode |
| 445 | */ |
| 446 | |
| 447 | /* disable the gasket */ |
| 448 | writew(0, &fec->eth->miigsk_enr); |
| 449 | |
| 450 | /* wait for the gasket to be disabled */ |
| 451 | while (readw(&fec->eth->miigsk_enr) & MIIGSK_ENR_READY) |
| 452 | udelay(2); |
| 453 | |
| 454 | /* configure gasket for RMII, 50 MHz, no loopback, and no echo */ |
| 455 | writew(MIIGSK_CFGR_IF_MODE_RMII, &fec->eth->miigsk_cfgr); |
| 456 | |
| 457 | /* re-enable the gasket */ |
| 458 | writew(MIIGSK_ENR_EN, &fec->eth->miigsk_enr); |
| 459 | |
| 460 | /* wait until MII gasket is ready */ |
| 461 | int max_loops = 10; |
| 462 | while ((readw(&fec->eth->miigsk_enr) & MIIGSK_ENR_READY) == 0) { |
| 463 | if (--max_loops <= 0) { |
| 464 | printf("WAIT for MII Gasket ready timed out\n"); |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | #endif |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 469 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 470 | #ifdef CONFIG_PHYLIB |
| 471 | if (!fec->phydev) |
| 472 | fec_eth_phy_config(edev); |
| 473 | if (fec->phydev) { |
| 474 | /* Start up the PHY */ |
| 475 | phy_startup(fec->phydev); |
| 476 | speed = fec->phydev->speed; |
| 477 | } else { |
| 478 | speed = _100BASET; |
| 479 | } |
| 480 | #else |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 481 | miiphy_wait_aneg(edev); |
Troy Kisky | 28774cb | 2012-02-07 14:08:46 +0000 | [diff] [blame] | 482 | speed = miiphy_speed(edev->name, fec->phy_id); |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 483 | miiphy_duplex(edev->name, fec->phy_id); |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 484 | #endif |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 485 | |
Troy Kisky | 28774cb | 2012-02-07 14:08:46 +0000 | [diff] [blame] | 486 | #ifdef FEC_QUIRK_ENET_MAC |
| 487 | { |
| 488 | u32 ecr = readl(&fec->eth->ecntrl) & ~FEC_ECNTRL_SPEED; |
| 489 | u32 rcr = (readl(&fec->eth->r_cntrl) & |
| 490 | ~(FEC_RCNTRL_RMII | FEC_RCNTRL_RMII_10T)) | |
| 491 | FEC_RCNTRL_RGMII | FEC_RCNTRL_MII_MODE; |
| 492 | if (speed == _1000BASET) |
| 493 | ecr |= FEC_ECNTRL_SPEED; |
| 494 | else if (speed != _100BASET) |
| 495 | rcr |= FEC_RCNTRL_RMII_10T; |
| 496 | writel(ecr, &fec->eth->ecntrl); |
| 497 | writel(rcr, &fec->eth->r_cntrl); |
| 498 | } |
| 499 | #endif |
| 500 | debug("%s:Speed=%i\n", __func__, speed); |
| 501 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 502 | /* |
| 503 | * Enable SmartDMA receive task |
| 504 | */ |
| 505 | fec_rx_task_enable(fec); |
| 506 | |
| 507 | udelay(100000); |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | static int fec_init(struct eth_device *dev, bd_t* bd) |
| 512 | { |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 513 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 514 | uint32_t mib_ptr = (uint32_t)&fec->eth->rmon_t_drop; |
Marek Vasut | 9eb3770 | 2011-09-11 18:05:31 +0000 | [diff] [blame] | 515 | uint32_t rcntrl; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 516 | uint32_t size; |
| 517 | int i, ret; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 518 | |
John Rigby | e9319f1 | 2010-10-13 14:31:08 -0600 | [diff] [blame] | 519 | /* Initialize MAC address */ |
| 520 | fec_set_hwaddr(dev); |
| 521 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 522 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 523 | * Allocate transmit descriptors, there are two in total. This |
| 524 | * allocation respects cache alignment. |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 525 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 526 | if (!fec->tbd_base) { |
| 527 | size = roundup(2 * sizeof(struct fec_bd), |
| 528 | ARCH_DMA_MINALIGN); |
| 529 | fec->tbd_base = memalign(ARCH_DMA_MINALIGN, size); |
| 530 | if (!fec->tbd_base) { |
| 531 | ret = -ENOMEM; |
| 532 | goto err1; |
| 533 | } |
| 534 | memset(fec->tbd_base, 0, size); |
| 535 | fec_tbd_init(fec); |
| 536 | flush_dcache_range((unsigned)fec->tbd_base, size); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 537 | } |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 538 | |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 539 | /* |
| 540 | * Allocate receive descriptors. This allocation respects cache |
| 541 | * alignment. |
| 542 | */ |
| 543 | if (!fec->rbd_base) { |
| 544 | size = roundup(FEC_RBD_NUM * sizeof(struct fec_bd), |
| 545 | ARCH_DMA_MINALIGN); |
| 546 | fec->rbd_base = memalign(ARCH_DMA_MINALIGN, size); |
| 547 | if (!fec->rbd_base) { |
| 548 | ret = -ENOMEM; |
| 549 | goto err2; |
| 550 | } |
| 551 | memset(fec->rbd_base, 0, size); |
| 552 | /* |
| 553 | * Initialize RxBD ring |
| 554 | */ |
| 555 | if (fec_rbd_init(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE) < 0) { |
| 556 | ret = -ENOMEM; |
| 557 | goto err3; |
| 558 | } |
| 559 | flush_dcache_range((unsigned)fec->rbd_base, |
| 560 | (unsigned)fec->rbd_base + size); |
| 561 | } |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 562 | |
| 563 | /* |
| 564 | * Set interrupt mask register |
| 565 | */ |
| 566 | writel(0x00000000, &fec->eth->imask); |
| 567 | |
| 568 | /* |
| 569 | * Clear FEC-Lite interrupt event register(IEVENT) |
| 570 | */ |
| 571 | writel(0xffffffff, &fec->eth->ievent); |
| 572 | |
| 573 | |
| 574 | /* |
| 575 | * Set FEC-Lite receive control register(R_CNTRL): |
| 576 | */ |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 577 | |
Marek Vasut | 9eb3770 | 2011-09-11 18:05:31 +0000 | [diff] [blame] | 578 | /* Start with frame length = 1518, common for all modes. */ |
| 579 | rcntrl = PKTSIZE << FEC_RCNTRL_MAX_FL_SHIFT; |
| 580 | if (fec->xcv_type == SEVENWIRE) |
| 581 | rcntrl |= FEC_RCNTRL_FCE; |
Jason Liu | 2ef2b95 | 2011-12-16 05:17:07 +0000 | [diff] [blame] | 582 | else if (fec->xcv_type == RGMII) |
| 583 | rcntrl |= FEC_RCNTRL_RGMII; |
Marek Vasut | a50a90c | 2011-09-11 18:05:32 +0000 | [diff] [blame] | 584 | else if (fec->xcv_type == RMII) |
| 585 | rcntrl |= FEC_RCNTRL_RMII; |
Marek Vasut | 9eb3770 | 2011-09-11 18:05:31 +0000 | [diff] [blame] | 586 | else /* MII mode */ |
| 587 | rcntrl |= FEC_RCNTRL_FCE | FEC_RCNTRL_MII_MODE; |
| 588 | |
| 589 | writel(rcntrl, &fec->eth->r_cntrl); |
| 590 | |
| 591 | if (fec->xcv_type == MII10 || fec->xcv_type == MII100) |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 592 | fec_mii_setspeed(fec); |
Marek Vasut | 9eb3770 | 2011-09-11 18:05:31 +0000 | [diff] [blame] | 593 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 594 | /* |
| 595 | * Set Opcode/Pause Duration Register |
| 596 | */ |
| 597 | writel(0x00010020, &fec->eth->op_pause); /* FIXME 0xffff0020; */ |
| 598 | writel(0x2, &fec->eth->x_wmrk); |
| 599 | /* |
| 600 | * Set multicast address filter |
| 601 | */ |
| 602 | writel(0x00000000, &fec->eth->gaddr1); |
| 603 | writel(0x00000000, &fec->eth->gaddr2); |
| 604 | |
| 605 | |
| 606 | /* clear MIB RAM */ |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 607 | for (i = mib_ptr; i <= mib_ptr + 0xfc; i += 4) |
| 608 | writel(0, i); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 609 | |
| 610 | /* FIFO receive start register */ |
| 611 | writel(0x520, &fec->eth->r_fstart); |
| 612 | |
| 613 | /* size and address of each buffer */ |
| 614 | writel(FEC_MAX_PKT_SIZE, &fec->eth->emrbr); |
| 615 | writel((uint32_t)fec->tbd_base, &fec->eth->etdsr); |
| 616 | writel((uint32_t)fec->rbd_base, &fec->eth->erdsr); |
| 617 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 618 | #ifndef CONFIG_PHYLIB |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 619 | if (fec->xcv_type != SEVENWIRE) |
| 620 | miiphy_restart_aneg(dev); |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 621 | #endif |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 622 | fec_open(dev); |
| 623 | return 0; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 624 | |
| 625 | err3: |
| 626 | free(fec->rbd_base); |
| 627 | err2: |
| 628 | free(fec->tbd_base); |
| 629 | err1: |
| 630 | return ret; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Halt the FEC engine |
| 635 | * @param[in] dev Our device to handle |
| 636 | */ |
| 637 | static void fec_halt(struct eth_device *dev) |
| 638 | { |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 639 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 640 | int counter = 0xffff; |
| 641 | |
| 642 | /* |
| 643 | * issue graceful stop command to the FEC transmitter if necessary |
| 644 | */ |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 645 | writel(FEC_TCNTRL_GTS | readl(&fec->eth->x_cntrl), |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 646 | &fec->eth->x_cntrl); |
| 647 | |
| 648 | debug("eth_halt: wait for stop regs\n"); |
| 649 | /* |
| 650 | * wait for graceful stop to register |
| 651 | */ |
| 652 | while ((counter--) && (!(readl(&fec->eth->ievent) & FEC_IEVENT_GRA))) |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 653 | udelay(1); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 654 | |
| 655 | /* |
| 656 | * Disable SmartDMA tasks |
| 657 | */ |
| 658 | fec_tx_task_disable(fec); |
| 659 | fec_rx_task_disable(fec); |
| 660 | |
| 661 | /* |
| 662 | * Disable the Ethernet Controller |
| 663 | * Note: this will also reset the BD index counter! |
| 664 | */ |
John Rigby | 740d6ae | 2010-01-25 23:12:57 -0700 | [diff] [blame] | 665 | writel(readl(&fec->eth->ecntrl) & ~FEC_ECNTRL_ETHER_EN, |
| 666 | &fec->eth->ecntrl); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 667 | fec->rbd_index = 0; |
| 668 | fec->tbd_index = 0; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 669 | debug("eth_halt: done\n"); |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * Transmit one frame |
| 674 | * @param[in] dev Our ethernet device to handle |
| 675 | * @param[in] packet Pointer to the data to be transmitted |
| 676 | * @param[in] length Data count in bytes |
| 677 | * @return 0 on success |
| 678 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 679 | static int fec_send(struct eth_device *dev, volatile void *packet, int length) |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 680 | { |
| 681 | unsigned int status; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 682 | uint32_t size; |
| 683 | uint32_t addr; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 684 | |
| 685 | /* |
| 686 | * This routine transmits one frame. This routine only accepts |
| 687 | * 6-byte Ethernet addresses. |
| 688 | */ |
| 689 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
| 690 | |
| 691 | /* |
| 692 | * Check for valid length of data. |
| 693 | */ |
| 694 | if ((length > 1500) || (length <= 0)) { |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 695 | printf("Payload (%d) too large\n", length); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 696 | return -1; |
| 697 | } |
| 698 | |
| 699 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 700 | * Setup the transmit buffer. We are always using the first buffer for |
| 701 | * transmission, the second will be empty and only used to stop the DMA |
| 702 | * engine. We also flush the packet to RAM here to avoid cache trouble. |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 703 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 704 | #ifdef CONFIG_FEC_MXC_SWAP_PACKET |
Marek Vasut | be7e87e | 2011-11-08 23:18:10 +0000 | [diff] [blame] | 705 | swap_packet((uint32_t *)packet, length); |
| 706 | #endif |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 707 | |
| 708 | addr = (uint32_t)packet; |
| 709 | size = roundup(length, ARCH_DMA_MINALIGN); |
| 710 | flush_dcache_range(addr, addr + size); |
| 711 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 712 | writew(length, &fec->tbd_base[fec->tbd_index].data_length); |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 713 | writel(addr, &fec->tbd_base[fec->tbd_index].data_pointer); |
| 714 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 715 | /* |
| 716 | * update BD's status now |
| 717 | * This block: |
| 718 | * - is always the last in a chain (means no chain) |
| 719 | * - should transmitt the CRC |
| 720 | * - might be the last BD in the list, so the address counter should |
| 721 | * wrap (-> keep the WRAP flag) |
| 722 | */ |
| 723 | status = readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_WRAP; |
| 724 | status |= FEC_TBD_LAST | FEC_TBD_TC | FEC_TBD_READY; |
| 725 | writew(status, &fec->tbd_base[fec->tbd_index].status); |
| 726 | |
| 727 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 728 | * Flush data cache. This code flushes both TX descriptors to RAM. |
| 729 | * After this code, the descriptors will be safely in RAM and we |
| 730 | * can start DMA. |
| 731 | */ |
| 732 | size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN); |
| 733 | addr = (uint32_t)fec->tbd_base; |
| 734 | flush_dcache_range(addr, addr + size); |
| 735 | |
| 736 | /* |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 737 | * Enable SmartDMA transmit task |
| 738 | */ |
| 739 | fec_tx_task_enable(fec); |
| 740 | |
| 741 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 742 | * Wait until frame is sent. On each turn of the wait cycle, we must |
| 743 | * invalidate data cache to see what's really in RAM. Also, we need |
| 744 | * barrier here. |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 745 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 746 | invalidate_dcache_range(addr, addr + size); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 747 | while (readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_READY) { |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 748 | udelay(1); |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 749 | invalidate_dcache_range(addr, addr + size); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 750 | } |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 751 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 752 | debug("fec_send: status 0x%x index %d\n", |
| 753 | readw(&fec->tbd_base[fec->tbd_index].status), |
| 754 | fec->tbd_index); |
| 755 | /* for next transmission use the other buffer */ |
| 756 | if (fec->tbd_index) |
| 757 | fec->tbd_index = 0; |
| 758 | else |
| 759 | fec->tbd_index = 1; |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Pull one frame from the card |
| 766 | * @param[in] dev Our ethernet device to handle |
| 767 | * @return Length of packet read |
| 768 | */ |
| 769 | static int fec_recv(struct eth_device *dev) |
| 770 | { |
| 771 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
| 772 | struct fec_bd *rbd = &fec->rbd_base[fec->rbd_index]; |
| 773 | unsigned long ievent; |
| 774 | int frame_length, len = 0; |
| 775 | struct nbuf *frame; |
| 776 | uint16_t bd_status; |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 777 | uint32_t addr, size; |
| 778 | int i; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 779 | uchar buff[FEC_MAX_PKT_SIZE]; |
| 780 | |
| 781 | /* |
| 782 | * Check if any critical events have happened |
| 783 | */ |
| 784 | ievent = readl(&fec->eth->ievent); |
| 785 | writel(ievent, &fec->eth->ievent); |
Marek Vasut | eda959f | 2011-10-24 23:40:03 +0000 | [diff] [blame] | 786 | debug("fec_recv: ievent 0x%lx\n", ievent); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 787 | if (ievent & FEC_IEVENT_BABR) { |
| 788 | fec_halt(dev); |
| 789 | fec_init(dev, fec->bd); |
| 790 | printf("some error: 0x%08lx\n", ievent); |
| 791 | return 0; |
| 792 | } |
| 793 | if (ievent & FEC_IEVENT_HBERR) { |
| 794 | /* Heartbeat error */ |
| 795 | writel(0x00000001 | readl(&fec->eth->x_cntrl), |
| 796 | &fec->eth->x_cntrl); |
| 797 | } |
| 798 | if (ievent & FEC_IEVENT_GRA) { |
| 799 | /* Graceful stop complete */ |
| 800 | if (readl(&fec->eth->x_cntrl) & 0x00000001) { |
| 801 | fec_halt(dev); |
| 802 | writel(~0x00000001 & readl(&fec->eth->x_cntrl), |
| 803 | &fec->eth->x_cntrl); |
| 804 | fec_init(dev, fec->bd); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 809 | * Read the buffer status. Before the status can be read, the data cache |
| 810 | * must be invalidated, because the data in RAM might have been changed |
| 811 | * by DMA. The descriptors are properly aligned to cachelines so there's |
| 812 | * no need to worry they'd overlap. |
| 813 | * |
| 814 | * WARNING: By invalidating the descriptor here, we also invalidate |
| 815 | * the descriptors surrounding this one. Therefore we can NOT change the |
| 816 | * contents of this descriptor nor the surrounding ones. The problem is |
| 817 | * that in order to mark the descriptor as processed, we need to change |
| 818 | * the descriptor. The solution is to mark the whole cache line when all |
| 819 | * descriptors in the cache line are processed. |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 820 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 821 | addr = (uint32_t)rbd; |
| 822 | addr &= ~(ARCH_DMA_MINALIGN - 1); |
| 823 | size = roundup(sizeof(struct fec_bd), ARCH_DMA_MINALIGN); |
| 824 | invalidate_dcache_range(addr, addr + size); |
| 825 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 826 | bd_status = readw(&rbd->status); |
| 827 | debug("fec_recv: status 0x%x\n", bd_status); |
| 828 | |
| 829 | if (!(bd_status & FEC_RBD_EMPTY)) { |
| 830 | if ((bd_status & FEC_RBD_LAST) && !(bd_status & FEC_RBD_ERR) && |
| 831 | ((readw(&rbd->data_length) - 4) > 14)) { |
| 832 | /* |
| 833 | * Get buffer address and size |
| 834 | */ |
| 835 | frame = (struct nbuf *)readl(&rbd->data_pointer); |
| 836 | frame_length = readw(&rbd->data_length) - 4; |
| 837 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 838 | * Invalidate data cache over the buffer |
| 839 | */ |
| 840 | addr = (uint32_t)frame; |
| 841 | size = roundup(frame_length, ARCH_DMA_MINALIGN); |
| 842 | invalidate_dcache_range(addr, addr + size); |
| 843 | |
| 844 | /* |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 845 | * Fill the buffer and pass it to upper layers |
| 846 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 847 | #ifdef CONFIG_FEC_MXC_SWAP_PACKET |
Marek Vasut | be7e87e | 2011-11-08 23:18:10 +0000 | [diff] [blame] | 848 | swap_packet((uint32_t *)frame->data, frame_length); |
| 849 | #endif |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 850 | memcpy(buff, frame->data, frame_length); |
| 851 | NetReceive(buff, frame_length); |
| 852 | len = frame_length; |
| 853 | } else { |
| 854 | if (bd_status & FEC_RBD_ERR) |
| 855 | printf("error frame: 0x%08lx 0x%08x\n", |
| 856 | (ulong)rbd->data_pointer, |
| 857 | bd_status); |
| 858 | } |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 859 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 860 | /* |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 861 | * Free the current buffer, restart the engine and move forward |
| 862 | * to the next buffer. Here we check if the whole cacheline of |
| 863 | * descriptors was already processed and if so, we mark it free |
| 864 | * as whole. |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 865 | */ |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 866 | size = RXDESC_PER_CACHELINE - 1; |
| 867 | if ((fec->rbd_index & size) == size) { |
| 868 | i = fec->rbd_index - size; |
| 869 | addr = (uint32_t)&fec->rbd_base[i]; |
| 870 | for (; i <= fec->rbd_index ; i++) { |
| 871 | fec_rbd_clean(i == (FEC_RBD_NUM - 1), |
| 872 | &fec->rbd_base[i]); |
| 873 | } |
| 874 | flush_dcache_range(addr, |
| 875 | addr + ARCH_DMA_MINALIGN); |
| 876 | } |
| 877 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 878 | fec_rx_task_enable(fec); |
| 879 | fec->rbd_index = (fec->rbd_index + 1) % FEC_RBD_NUM; |
| 880 | } |
| 881 | debug("fec_recv: stop\n"); |
| 882 | |
| 883 | return len; |
| 884 | } |
| 885 | |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 886 | static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 887 | { |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 888 | struct eth_device *edev; |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 889 | struct fec_priv *fec; |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 890 | struct mii_dev *bus; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 891 | unsigned char ethaddr[6]; |
Marek Vasut | e382fb4 | 2011-09-11 18:05:37 +0000 | [diff] [blame] | 892 | uint32_t start; |
| 893 | int ret = 0; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 894 | |
| 895 | /* create and fill edev struct */ |
| 896 | edev = (struct eth_device *)malloc(sizeof(struct eth_device)); |
| 897 | if (!edev) { |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 898 | puts("fec_mxc: not enough malloc memory for eth_device\n"); |
Marek Vasut | e382fb4 | 2011-09-11 18:05:37 +0000 | [diff] [blame] | 899 | ret = -ENOMEM; |
| 900 | goto err1; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 901 | } |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 902 | |
| 903 | fec = (struct fec_priv *)malloc(sizeof(struct fec_priv)); |
| 904 | if (!fec) { |
| 905 | puts("fec_mxc: not enough malloc memory for fec_priv\n"); |
Marek Vasut | e382fb4 | 2011-09-11 18:05:37 +0000 | [diff] [blame] | 906 | ret = -ENOMEM; |
| 907 | goto err2; |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Nobuhiro Iwamatsu | de0b957 | 2010-10-19 14:03:42 +0900 | [diff] [blame] | 910 | memset(edev, 0, sizeof(*edev)); |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 911 | memset(fec, 0, sizeof(*fec)); |
| 912 | |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 913 | edev->priv = fec; |
| 914 | edev->init = fec_init; |
| 915 | edev->send = fec_send; |
| 916 | edev->recv = fec_recv; |
| 917 | edev->halt = fec_halt; |
Heiko Schocher | fb57ec9 | 2010-04-27 07:43:52 +0200 | [diff] [blame] | 918 | edev->write_hwaddr = fec_set_hwaddr; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 919 | |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 920 | fec->eth = (struct ethernet_regs *)base_addr; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 921 | fec->bd = bd; |
| 922 | |
Marek Vasut | 392b850 | 2011-09-11 18:05:33 +0000 | [diff] [blame] | 923 | fec->xcv_type = CONFIG_FEC_XCV_TYPE; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 924 | |
| 925 | /* Reset chip. */ |
John Rigby | cb17b92 | 2010-01-25 23:12:55 -0700 | [diff] [blame] | 926 | writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_RESET, &fec->eth->ecntrl); |
Marek Vasut | e382fb4 | 2011-09-11 18:05:37 +0000 | [diff] [blame] | 927 | start = get_timer(0); |
| 928 | while (readl(&fec->eth->ecntrl) & FEC_ECNTRL_RESET) { |
| 929 | if (get_timer(start) > (CONFIG_SYS_HZ * 5)) { |
| 930 | printf("FEC MXC: Timeout reseting chip\n"); |
| 931 | goto err3; |
| 932 | } |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 933 | udelay(10); |
Marek Vasut | e382fb4 | 2011-09-11 18:05:37 +0000 | [diff] [blame] | 934 | } |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 935 | |
| 936 | /* |
| 937 | * Set interrupt mask register |
| 938 | */ |
| 939 | writel(0x00000000, &fec->eth->imask); |
| 940 | |
| 941 | /* |
| 942 | * Clear FEC-Lite interrupt event register(IEVENT) |
| 943 | */ |
| 944 | writel(0xffffffff, &fec->eth->ievent); |
| 945 | |
| 946 | /* |
| 947 | * Set FEC-Lite receive control register(R_CNTRL): |
| 948 | */ |
| 949 | /* |
| 950 | * Frame length=1518; MII mode; |
| 951 | */ |
Marek Vasut | 9eb3770 | 2011-09-11 18:05:31 +0000 | [diff] [blame] | 952 | writel((PKTSIZE << FEC_RCNTRL_MAX_FL_SHIFT) | FEC_RCNTRL_FCE | |
| 953 | FEC_RCNTRL_MII_MODE, &fec->eth->r_cntrl); |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 954 | fec_mii_setspeed(fec); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 955 | |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 956 | if (dev_id == -1) { |
| 957 | sprintf(edev->name, "FEC"); |
| 958 | fec->dev_id = 0; |
| 959 | } else { |
| 960 | sprintf(edev->name, "FEC%i", dev_id); |
| 961 | fec->dev_id = dev_id; |
| 962 | } |
| 963 | fec->phy_id = phy_id; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 964 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 965 | bus = mdio_alloc(); |
| 966 | if (!bus) { |
| 967 | printf("mdio_alloc failed\n"); |
| 968 | ret = -ENOMEM; |
| 969 | goto err3; |
| 970 | } |
| 971 | bus->read = fec_phy_read; |
| 972 | bus->write = fec_phy_write; |
| 973 | sprintf(bus->name, edev->name); |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 974 | #ifdef CONFIG_MX28 |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 975 | /* |
| 976 | * The i.MX28 has two ethernet interfaces, but they are not equal. |
| 977 | * Only the first one can access the MDIO bus. |
| 978 | */ |
| 979 | bus->priv = (struct ethernet_regs *)MXS_ENET0_BASE; |
| 980 | #else |
| 981 | bus->priv = fec->eth; |
| 982 | #endif |
| 983 | ret = mdio_register(bus); |
| 984 | if (ret) { |
| 985 | printf("mdio_register failed\n"); |
| 986 | free(bus); |
| 987 | ret = -ENOMEM; |
| 988 | goto err3; |
| 989 | } |
| 990 | fec->bus = bus; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 991 | eth_register(edev); |
| 992 | |
Fabio Estevam | be252b6 | 2011-12-20 05:46:31 +0000 | [diff] [blame] | 993 | if (fec_get_hwaddr(edev, dev_id, ethaddr) == 0) { |
| 994 | debug("got MAC%d address from fuse: %pM\n", dev_id, ethaddr); |
Stefano Babic | 4294b24 | 2010-02-01 14:51:30 +0100 | [diff] [blame] | 995 | memcpy(edev->enetaddr, ethaddr, 6); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 996 | } |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 997 | /* Configure phy */ |
| 998 | fec_eth_phy_config(edev); |
Marek Vasut | e382fb4 | 2011-09-11 18:05:37 +0000 | [diff] [blame] | 999 | return ret; |
| 1000 | |
| 1001 | err3: |
| 1002 | free(fec); |
| 1003 | err2: |
| 1004 | free(edev); |
| 1005 | err1: |
| 1006 | return ret; |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 1007 | } |
| 1008 | |
Eric Nelson | 5c1ad3e | 2012-03-15 18:33:25 +0000 | [diff] [blame] | 1009 | #ifndef CONFIG_FEC_MXC_MULTI |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 1010 | int fecmxc_initialize(bd_t *bd) |
| 1011 | { |
| 1012 | int lout = 1; |
| 1013 | |
| 1014 | debug("eth_init: fec_probe(bd)\n"); |
Marek Vasut | 9e27e9d | 2011-09-16 01:13:47 +0200 | [diff] [blame] | 1015 | lout = fec_probe(bd, -1, CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE); |
| 1016 | |
| 1017 | return lout; |
| 1018 | } |
| 1019 | #endif |
| 1020 | |
| 1021 | int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr) |
| 1022 | { |
| 1023 | int lout = 1; |
| 1024 | |
| 1025 | debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr); |
| 1026 | lout = fec_probe(bd, dev_id, phy_id, addr); |
Ilya Yanok | 0b23fb3 | 2009-07-21 19:32:21 +0400 | [diff] [blame] | 1027 | |
| 1028 | return lout; |
| 1029 | } |
Marek Vasut | 2e5f442 | 2011-09-11 18:05:36 +0000 | [diff] [blame] | 1030 | |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 1031 | #ifndef CONFIG_PHYLIB |
Marek Vasut | 2e5f442 | 2011-09-11 18:05:36 +0000 | [diff] [blame] | 1032 | int fecmxc_register_mii_postcall(struct eth_device *dev, int (*cb)(int)) |
| 1033 | { |
| 1034 | struct fec_priv *fec = (struct fec_priv *)dev->priv; |
| 1035 | fec->mii_postcall = cb; |
| 1036 | return 0; |
| 1037 | } |
Troy Kisky | 13947f4 | 2012-02-07 14:08:47 +0000 | [diff] [blame] | 1038 | #endif |