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