wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This provides a bit-banged interface to the ethernet MII management |
| 10 | * channel. |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | c74c8e6 | 2015-04-05 16:07:39 -0600 | [diff] [blame] | 14 | #include <dm.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 15 | #include <miiphy.h> |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 16 | #include <phy.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 17 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 18 | #include <asm/types.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <malloc.h> |
| 21 | #include <net.h> |
| 22 | |
| 23 | /* local debug macro */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 24 | #undef MII_DEBUG |
| 25 | |
| 26 | #undef debug |
| 27 | #ifdef MII_DEBUG |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 28 | #define debug(fmt, args...) printf(fmt, ##args) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 29 | #else |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 30 | #define debug(fmt, args...) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 31 | #endif /* MII_DEBUG */ |
| 32 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 33 | static struct list_head mii_devs; |
| 34 | static struct mii_dev *current_mii; |
| 35 | |
Mike Frysinger | 0daac97 | 2010-07-27 18:35:09 -0400 | [diff] [blame] | 36 | /* |
| 37 | * Lookup the mii_dev struct by the registered device name. |
| 38 | */ |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 39 | struct mii_dev *miiphy_get_dev_by_name(const char *devname) |
Mike Frysinger | 0daac97 | 2010-07-27 18:35:09 -0400 | [diff] [blame] | 40 | { |
| 41 | struct list_head *entry; |
| 42 | struct mii_dev *dev; |
| 43 | |
| 44 | if (!devname) { |
| 45 | printf("NULL device name!\n"); |
| 46 | return NULL; |
| 47 | } |
| 48 | |
| 49 | list_for_each(entry, &mii_devs) { |
| 50 | dev = list_entry(entry, struct mii_dev, link); |
| 51 | if (strcmp(dev->name, devname) == 0) |
| 52 | return dev; |
| 53 | } |
| 54 | |
Mike Frysinger | 0daac97 | 2010-07-27 18:35:09 -0400 | [diff] [blame] | 55 | return NULL; |
| 56 | } |
| 57 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 58 | /***************************************************************************** |
| 59 | * |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 60 | * Initialize global data. Need to be called before any other miiphy routine. |
| 61 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 62 | void miiphy_init(void) |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 63 | { |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 64 | INIT_LIST_HEAD(&mii_devs); |
Larry Johnson | 298035d | 2007-10-31 11:21:29 -0500 | [diff] [blame] | 65 | current_mii = NULL; |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 68 | static int legacy_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg) |
| 69 | { |
| 70 | unsigned short val; |
| 71 | int ret; |
| 72 | struct legacy_mii_dev *ldev = bus->priv; |
| 73 | |
| 74 | ret = ldev->read(bus->name, addr, reg, &val); |
| 75 | |
| 76 | return ret ? -1 : (int)val; |
| 77 | } |
| 78 | |
| 79 | static int legacy_miiphy_write(struct mii_dev *bus, int addr, int devad, |
| 80 | int reg, u16 val) |
| 81 | { |
| 82 | struct legacy_mii_dev *ldev = bus->priv; |
| 83 | |
| 84 | return ldev->write(bus->name, addr, reg, val); |
| 85 | } |
| 86 | |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 87 | /***************************************************************************** |
| 88 | * |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 89 | * Register read and write MII access routines for the device <name>. |
Andy Fleming | 1cdabc4 | 2011-10-31 09:46:13 -0500 | [diff] [blame] | 90 | * This API is now deprecated. Please use mdio_alloc and mdio_register, instead. |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 91 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 92 | void miiphy_register(const char *name, |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 93 | int (*read)(const char *devname, unsigned char addr, |
Wolfgang Denk | f915c93 | 2011-12-07 08:35:14 +0100 | [diff] [blame] | 94 | unsigned char reg, unsigned short *value), |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 95 | int (*write)(const char *devname, unsigned char addr, |
Wolfgang Denk | f915c93 | 2011-12-07 08:35:14 +0100 | [diff] [blame] | 96 | unsigned char reg, unsigned short value)) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 97 | { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 98 | struct mii_dev *new_dev; |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 99 | struct legacy_mii_dev *ldev; |
Laurence Withers | 07c0763 | 2011-07-14 23:21:45 +0000 | [diff] [blame] | 100 | |
| 101 | BUG_ON(strlen(name) >= MDIO_NAME_LEN); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 102 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 103 | /* check if we have unique name */ |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 104 | new_dev = miiphy_get_dev_by_name(name); |
Mike Frysinger | 0daac97 | 2010-07-27 18:35:09 -0400 | [diff] [blame] | 105 | if (new_dev) { |
| 106 | printf("miiphy_register: non unique device name '%s'\n", name); |
| 107 | return; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* allocate memory */ |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 111 | new_dev = mdio_alloc(); |
| 112 | ldev = malloc(sizeof(*ldev)); |
| 113 | |
| 114 | if (new_dev == NULL || ldev == NULL) { |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 115 | printf("miiphy_register: cannot allocate memory for '%s'\n", |
Larry Johnson | 298035d | 2007-10-31 11:21:29 -0500 | [diff] [blame] | 116 | name); |
Peng Fan | 746da1b | 2015-11-26 10:26:59 +0800 | [diff] [blame] | 117 | free(ldev); |
| 118 | mdio_free(new_dev); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 119 | return; |
| 120 | } |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 121 | |
| 122 | /* initalize mii_dev struct fields */ |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 123 | new_dev->read = legacy_miiphy_read; |
| 124 | new_dev->write = legacy_miiphy_write; |
Laurence Withers | 07c0763 | 2011-07-14 23:21:45 +0000 | [diff] [blame] | 125 | strncpy(new_dev->name, name, MDIO_NAME_LEN); |
| 126 | new_dev->name[MDIO_NAME_LEN - 1] = 0; |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 127 | ldev->read = read; |
| 128 | ldev->write = write; |
| 129 | new_dev->priv = ldev; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 130 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 131 | debug("miiphy_register: added '%s', read=0x%08lx, write=0x%08lx\n", |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 132 | new_dev->name, ldev->read, ldev->write); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 133 | |
| 134 | /* add it to the list */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 135 | list_add_tail(&new_dev->link, &mii_devs); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 136 | |
| 137 | if (!current_mii) |
| 138 | current_mii = new_dev; |
| 139 | } |
| 140 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 141 | struct mii_dev *mdio_alloc(void) |
| 142 | { |
| 143 | struct mii_dev *bus; |
| 144 | |
| 145 | bus = malloc(sizeof(*bus)); |
| 146 | if (!bus) |
| 147 | return bus; |
| 148 | |
| 149 | memset(bus, 0, sizeof(*bus)); |
| 150 | |
| 151 | /* initalize mii_dev struct fields */ |
| 152 | INIT_LIST_HEAD(&bus->link); |
| 153 | |
| 154 | return bus; |
| 155 | } |
| 156 | |
Bin Meng | cb6baca | 2015-10-07 21:32:37 -0700 | [diff] [blame] | 157 | void mdio_free(struct mii_dev *bus) |
| 158 | { |
| 159 | free(bus); |
| 160 | } |
| 161 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 162 | int mdio_register(struct mii_dev *bus) |
| 163 | { |
Peng Fan | d39449b | 2015-11-24 17:03:47 +0800 | [diff] [blame] | 164 | if (!bus || !bus->read || !bus->write) |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 165 | return -1; |
| 166 | |
| 167 | /* check if we have unique name */ |
| 168 | if (miiphy_get_dev_by_name(bus->name)) { |
| 169 | printf("mdio_register: non unique device name '%s'\n", |
| 170 | bus->name); |
| 171 | return -1; |
| 172 | } |
| 173 | |
| 174 | /* add it to the list */ |
| 175 | list_add_tail(&bus->link, &mii_devs); |
| 176 | |
| 177 | if (!current_mii) |
| 178 | current_mii = bus; |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Bin Meng | cb6baca | 2015-10-07 21:32:37 -0700 | [diff] [blame] | 183 | int mdio_unregister(struct mii_dev *bus) |
| 184 | { |
| 185 | if (!bus) |
| 186 | return 0; |
| 187 | |
| 188 | /* delete it from the list */ |
| 189 | list_del(&bus->link); |
| 190 | |
| 191 | if (current_mii == bus) |
| 192 | current_mii = NULL; |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 197 | void mdio_list_devices(void) |
| 198 | { |
| 199 | struct list_head *entry; |
| 200 | |
| 201 | list_for_each(entry, &mii_devs) { |
| 202 | int i; |
| 203 | struct mii_dev *bus = list_entry(entry, struct mii_dev, link); |
| 204 | |
| 205 | printf("%s:\n", bus->name); |
| 206 | |
| 207 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
| 208 | struct phy_device *phydev = bus->phymap[i]; |
| 209 | |
| 210 | if (phydev) { |
| 211 | printf("%d - %s", i, phydev->drv->name); |
| 212 | |
| 213 | if (phydev->dev) |
| 214 | printf(" <--> %s\n", phydev->dev->name); |
| 215 | else |
| 216 | printf("\n"); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 222 | int miiphy_set_current_dev(const char *devname) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 223 | { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 224 | struct mii_dev *dev; |
| 225 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 226 | dev = miiphy_get_dev_by_name(devname); |
Mike Frysinger | 0daac97 | 2010-07-27 18:35:09 -0400 | [diff] [blame] | 227 | if (dev) { |
| 228 | current_mii = dev; |
| 229 | return 0; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 232 | printf("No such device: %s\n", devname); |
| 233 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 234 | return 1; |
| 235 | } |
| 236 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 237 | struct mii_dev *mdio_get_current_dev(void) |
| 238 | { |
| 239 | return current_mii; |
| 240 | } |
| 241 | |
| 242 | struct phy_device *mdio_phydev_for_ethname(const char *ethname) |
| 243 | { |
| 244 | struct list_head *entry; |
| 245 | struct mii_dev *bus; |
| 246 | |
| 247 | list_for_each(entry, &mii_devs) { |
| 248 | int i; |
| 249 | bus = list_entry(entry, struct mii_dev, link); |
| 250 | |
| 251 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
| 252 | if (!bus->phymap[i] || !bus->phymap[i]->dev) |
| 253 | continue; |
| 254 | |
| 255 | if (strcmp(bus->phymap[i]->dev->name, ethname) == 0) |
| 256 | return bus->phymap[i]; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | printf("%s is not a known ethernet\n", ethname); |
| 261 | return NULL; |
| 262 | } |
| 263 | |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 264 | const char *miiphy_get_current_dev(void) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 265 | { |
| 266 | if (current_mii) |
| 267 | return current_mii->name; |
| 268 | |
| 269 | return NULL; |
| 270 | } |
| 271 | |
Mike Frysinger | ede16ea | 2010-07-27 18:35:10 -0400 | [diff] [blame] | 272 | static struct mii_dev *miiphy_get_active_dev(const char *devname) |
| 273 | { |
| 274 | /* If the current mii is the one we want, return it */ |
| 275 | if (current_mii) |
| 276 | if (strcmp(current_mii->name, devname) == 0) |
| 277 | return current_mii; |
| 278 | |
| 279 | /* Otherwise, set the active one to the one we want */ |
| 280 | if (miiphy_set_current_dev(devname)) |
| 281 | return NULL; |
| 282 | else |
| 283 | return current_mii; |
| 284 | } |
| 285 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 286 | /***************************************************************************** |
| 287 | * |
| 288 | * Read to variable <value> from the PHY attached to device <devname>, |
| 289 | * use PHY address <addr> and register <reg>. |
| 290 | * |
Andy Fleming | 1cdabc4 | 2011-10-31 09:46:13 -0500 | [diff] [blame] | 291 | * This API is deprecated. Use phy_read on a phy_device found via phy_connect |
| 292 | * |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 293 | * Returns: |
| 294 | * 0 on success |
| 295 | */ |
Wolfgang Denk | f915c93 | 2011-12-07 08:35:14 +0100 | [diff] [blame] | 296 | int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, |
Larry Johnson | 298035d | 2007-10-31 11:21:29 -0500 | [diff] [blame] | 297 | unsigned short *value) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 298 | { |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 299 | struct mii_dev *bus; |
Anatolij Gustschin | d67d5d5 | 2011-04-30 02:17:44 +0000 | [diff] [blame] | 300 | int ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 301 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 302 | bus = miiphy_get_active_dev(devname); |
Anatolij Gustschin | d67d5d5 | 2011-04-30 02:17:44 +0000 | [diff] [blame] | 303 | if (!bus) |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 304 | return 1; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 305 | |
Anatolij Gustschin | d67d5d5 | 2011-04-30 02:17:44 +0000 | [diff] [blame] | 306 | ret = bus->read(bus, addr, MDIO_DEVAD_NONE, reg); |
| 307 | if (ret < 0) |
| 308 | return 1; |
| 309 | |
| 310 | *value = (unsigned short)ret; |
| 311 | return 0; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /***************************************************************************** |
| 315 | * |
| 316 | * Write <value> to the PHY attached to device <devname>, |
| 317 | * use PHY address <addr> and register <reg>. |
| 318 | * |
Andy Fleming | 1cdabc4 | 2011-10-31 09:46:13 -0500 | [diff] [blame] | 319 | * This API is deprecated. Use phy_write on a phy_device found by phy_connect |
| 320 | * |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 321 | * Returns: |
| 322 | * 0 on success |
| 323 | */ |
Wolfgang Denk | f915c93 | 2011-12-07 08:35:14 +0100 | [diff] [blame] | 324 | int miiphy_write(const char *devname, unsigned char addr, unsigned char reg, |
Larry Johnson | 298035d | 2007-10-31 11:21:29 -0500 | [diff] [blame] | 325 | unsigned short value) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 326 | { |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 327 | struct mii_dev *bus; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 328 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 329 | bus = miiphy_get_active_dev(devname); |
| 330 | if (bus) |
| 331 | return bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 332 | |
Mike Frysinger | 0daac97 | 2010-07-27 18:35:09 -0400 | [diff] [blame] | 333 | return 1; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /***************************************************************************** |
| 337 | * |
| 338 | * Print out list of registered MII capable devices. |
| 339 | */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 340 | void miiphy_listdev(void) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 341 | { |
| 342 | struct list_head *entry; |
| 343 | struct mii_dev *dev; |
| 344 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 345 | puts("MII devices: "); |
| 346 | list_for_each(entry, &mii_devs) { |
| 347 | dev = list_entry(entry, struct mii_dev, link); |
| 348 | printf("'%s' ", dev->name); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 349 | } |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 350 | puts("\n"); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 351 | |
| 352 | if (current_mii) |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 353 | printf("Current device: '%s'\n", current_mii->name); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 354 | } |
| 355 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 356 | /***************************************************************************** |
| 357 | * |
| 358 | * Read the OUI, manufacture's model number, and revision number. |
| 359 | * |
| 360 | * OUI: 22 bits (unsigned int) |
| 361 | * Model: 6 bits (unsigned char) |
| 362 | * Revision: 4 bits (unsigned char) |
| 363 | * |
Andy Fleming | 1cdabc4 | 2011-10-31 09:46:13 -0500 | [diff] [blame] | 364 | * This API is deprecated. |
| 365 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 366 | * Returns: |
| 367 | * 0 on success |
| 368 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 369 | int miiphy_info(const char *devname, unsigned char addr, unsigned int *oui, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 370 | unsigned char *model, unsigned char *rev) |
| 371 | { |
| 372 | unsigned int reg = 0; |
wdenk | 8bf3b00 | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 373 | unsigned short tmp; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 374 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 375 | if (miiphy_read(devname, addr, MII_PHYSID2, &tmp) != 0) { |
| 376 | debug("PHY ID register 2 read failed\n"); |
| 377 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | } |
wdenk | 8bf3b00 | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 379 | reg = tmp; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 380 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 381 | debug("MII_PHYSID2 @ 0x%x = 0x%04x\n", addr, reg); |
Shinya Kuribayashi | 26c7bab | 2008-01-19 10:25:59 +0900 | [diff] [blame] | 382 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 383 | if (reg == 0xFFFF) { |
| 384 | /* No physical device present at this address */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 385 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 388 | if (miiphy_read(devname, addr, MII_PHYSID1, &tmp) != 0) { |
| 389 | debug("PHY ID register 1 read failed\n"); |
| 390 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 391 | } |
wdenk | 8bf3b00 | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 392 | reg |= tmp << 16; |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 393 | debug("PHY_PHYIDR[1,2] @ 0x%x = 0x%08x\n", addr, reg); |
Shinya Kuribayashi | 26c7bab | 2008-01-19 10:25:59 +0900 | [diff] [blame] | 394 | |
Larry Johnson | 298035d | 2007-10-31 11:21:29 -0500 | [diff] [blame] | 395 | *oui = (reg >> 10); |
| 396 | *model = (unsigned char)((reg >> 4) & 0x0000003F); |
| 397 | *rev = (unsigned char)(reg & 0x0000000F); |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 398 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 401 | #ifndef CONFIG_PHYLIB |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 402 | /***************************************************************************** |
| 403 | * |
| 404 | * Reset the PHY. |
Andy Fleming | 1cdabc4 | 2011-10-31 09:46:13 -0500 | [diff] [blame] | 405 | * |
| 406 | * This API is deprecated. Use PHYLIB. |
| 407 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 408 | * Returns: |
| 409 | * 0 on success |
| 410 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 411 | int miiphy_reset(const char *devname, unsigned char addr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 412 | { |
| 413 | unsigned short reg; |
Stefan Roese | ab5a0dc | 2010-02-02 13:43:48 +0100 | [diff] [blame] | 414 | int timeout = 500; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 416 | if (miiphy_read(devname, addr, MII_BMCR, ®) != 0) { |
| 417 | debug("PHY status read failed\n"); |
| 418 | return -1; |
Wolfgang Denk | f89920c | 2005-08-12 23:15:53 +0200 | [diff] [blame] | 419 | } |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 420 | if (miiphy_write(devname, addr, MII_BMCR, reg | BMCR_RESET) != 0) { |
| 421 | debug("PHY reset failed\n"); |
| 422 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 423 | } |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 424 | #ifdef CONFIG_PHY_RESET_DELAY |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 425 | udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */ |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 426 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 427 | /* |
| 428 | * Poll the control register for the reset bit to go to 0 (it is |
| 429 | * auto-clearing). This should happen within 0.5 seconds per the |
| 430 | * IEEE spec. |
| 431 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 432 | reg = 0x8000; |
Stefan Roese | ab5a0dc | 2010-02-02 13:43:48 +0100 | [diff] [blame] | 433 | while (((reg & 0x8000) != 0) && timeout--) { |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 434 | if (miiphy_read(devname, addr, MII_BMCR, ®) != 0) { |
Stefan Roese | ab5a0dc | 2010-02-02 13:43:48 +0100 | [diff] [blame] | 435 | debug("PHY status read failed\n"); |
| 436 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 437 | } |
Stefan Roese | ab5a0dc | 2010-02-02 13:43:48 +0100 | [diff] [blame] | 438 | udelay(1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 439 | } |
| 440 | if ((reg & 0x8000) == 0) { |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 441 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 442 | } else { |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 443 | puts("PHY reset timed out\n"); |
| 444 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 445 | } |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 446 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 447 | } |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 448 | #endif /* !PHYLIB */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 450 | /***************************************************************************** |
| 451 | * |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 452 | * Determine the ethernet speed (10/100/1000). Return 10 on error. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 453 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 454 | int miiphy_speed(const char *devname, unsigned char addr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 455 | { |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 456 | u16 bmcr, anlpar; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 457 | |
wdenk | 6fb6af6 | 2004-03-23 23:20:24 +0000 | [diff] [blame] | 458 | #if defined(CONFIG_PHY_GIGE) |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 459 | u16 btsr; |
| 460 | |
| 461 | /* |
| 462 | * Check for 1000BASE-X. If it is supported, then assume that the speed |
| 463 | * is 1000. |
| 464 | */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 465 | if (miiphy_is_1000base_x(devname, addr)) |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 466 | return _1000BASET; |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 467 | |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 468 | /* |
| 469 | * No 1000BASE-X, so assume 1000BASE-T/100BASE-TX/10BASE-T register set. |
| 470 | */ |
| 471 | /* Check for 1000BASE-T. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 472 | if (miiphy_read(devname, addr, MII_STAT1000, &btsr)) { |
| 473 | printf("PHY 1000BT status"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 474 | goto miiphy_read_failed; |
| 475 | } |
| 476 | if (btsr != 0xFFFF && |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 477 | (btsr & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD))) |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 478 | return _1000BASET; |
wdenk | 6fb6af6 | 2004-03-23 23:20:24 +0000 | [diff] [blame] | 479 | #endif /* CONFIG_PHY_GIGE */ |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 480 | |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 481 | /* Check Basic Management Control Register first. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 482 | if (miiphy_read(devname, addr, MII_BMCR, &bmcr)) { |
| 483 | printf("PHY speed"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 484 | goto miiphy_read_failed; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 485 | } |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 486 | /* Check if auto-negotiation is on. */ |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 487 | if (bmcr & BMCR_ANENABLE) { |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 488 | /* Get auto-negotiation results. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 489 | if (miiphy_read(devname, addr, MII_LPA, &anlpar)) { |
| 490 | printf("PHY AN speed"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 491 | goto miiphy_read_failed; |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 492 | } |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 493 | return (anlpar & LPA_100) ? _100BASET : _10BASET; |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 494 | } |
| 495 | /* Get speed from basic control settings. */ |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 496 | return (bmcr & BMCR_SPEED100) ? _100BASET : _10BASET; |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 497 | |
Michael Zaidman | 5f84195 | 2010-02-28 16:28:25 +0200 | [diff] [blame] | 498 | miiphy_read_failed: |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 499 | printf(" read failed, assuming 10BASE-T\n"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 500 | return _10BASET; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 501 | } |
| 502 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 503 | /***************************************************************************** |
| 504 | * |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 505 | * Determine full/half duplex. Return half on error. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 506 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 507 | int miiphy_duplex(const char *devname, unsigned char addr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 508 | { |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 509 | u16 bmcr, anlpar; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 510 | |
wdenk | 6fb6af6 | 2004-03-23 23:20:24 +0000 | [diff] [blame] | 511 | #if defined(CONFIG_PHY_GIGE) |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 512 | u16 btsr; |
| 513 | |
| 514 | /* Check for 1000BASE-X. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 515 | if (miiphy_is_1000base_x(devname, addr)) { |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 516 | /* 1000BASE-X */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 517 | if (miiphy_read(devname, addr, MII_LPA, &anlpar)) { |
| 518 | printf("1000BASE-X PHY AN duplex"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 519 | goto miiphy_read_failed; |
| 520 | } |
| 521 | } |
| 522 | /* |
| 523 | * No 1000BASE-X, so assume 1000BASE-T/100BASE-TX/10BASE-T register set. |
| 524 | */ |
| 525 | /* Check for 1000BASE-T. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 526 | if (miiphy_read(devname, addr, MII_STAT1000, &btsr)) { |
| 527 | printf("PHY 1000BT status"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 528 | goto miiphy_read_failed; |
| 529 | } |
| 530 | if (btsr != 0xFFFF) { |
| 531 | if (btsr & PHY_1000BTSR_1000FD) { |
| 532 | return FULL; |
| 533 | } else if (btsr & PHY_1000BTSR_1000HD) { |
| 534 | return HALF; |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
wdenk | 6fb6af6 | 2004-03-23 23:20:24 +0000 | [diff] [blame] | 537 | #endif /* CONFIG_PHY_GIGE */ |
wdenk | 855a496 | 2004-03-14 18:23:55 +0000 | [diff] [blame] | 538 | |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 539 | /* Check Basic Management Control Register first. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 540 | if (miiphy_read(devname, addr, MII_BMCR, &bmcr)) { |
| 541 | puts("PHY duplex"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 542 | goto miiphy_read_failed; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 543 | } |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 544 | /* Check if auto-negotiation is on. */ |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 545 | if (bmcr & BMCR_ANENABLE) { |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 546 | /* Get auto-negotiation results. */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 547 | if (miiphy_read(devname, addr, MII_LPA, &anlpar)) { |
| 548 | puts("PHY AN duplex"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 549 | goto miiphy_read_failed; |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 550 | } |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 551 | return (anlpar & (LPA_10FULL | LPA_100FULL)) ? |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 552 | FULL : HALF; |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 553 | } |
| 554 | /* Get speed from basic control settings. */ |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 555 | return (bmcr & BMCR_FULLDPLX) ? FULL : HALF; |
wdenk | a56bd92 | 2004-06-06 23:13:55 +0000 | [diff] [blame] | 556 | |
Michael Zaidman | 5f84195 | 2010-02-28 16:28:25 +0200 | [diff] [blame] | 557 | miiphy_read_failed: |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 558 | printf(" read failed, assuming half duplex\n"); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 559 | return HALF; |
| 560 | } |
| 561 | |
| 562 | /***************************************************************************** |
| 563 | * |
| 564 | * Return 1 if PHY supports 1000BASE-X, 0 if PHY supports 10BASE-T/100BASE-TX/ |
| 565 | * 1000BASE-T, or on error. |
| 566 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 567 | int miiphy_is_1000base_x(const char *devname, unsigned char addr) |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 568 | { |
| 569 | #if defined(CONFIG_PHY_GIGE) |
| 570 | u16 exsr; |
| 571 | |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 572 | if (miiphy_read(devname, addr, MII_ESTATUS, &exsr)) { |
| 573 | printf("PHY extended status read failed, assuming no " |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 574 | "1000BASE-X\n"); |
| 575 | return 0; |
| 576 | } |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 577 | return 0 != (exsr & (ESTATUS_1000XF | ESTATUS_1000XH)); |
Larry Johnson | 71bc6e6 | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 578 | #else |
| 579 | return 0; |
| 580 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 583 | #ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 584 | /***************************************************************************** |
| 585 | * |
| 586 | * Determine link status |
| 587 | */ |
Mike Frysinger | 5700bb6 | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 588 | int miiphy_link(const char *devname, unsigned char addr) |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 589 | { |
| 590 | unsigned short reg; |
| 591 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 592 | /* dummy read; needed to latch some phys */ |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 593 | (void)miiphy_read(devname, addr, MII_BMSR, ®); |
| 594 | if (miiphy_read(devname, addr, MII_BMSR, ®)) { |
| 595 | puts("MII_BMSR read failed, assuming no link\n"); |
| 596 | return 0; |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* Determine if a link is active */ |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 600 | if ((reg & BMSR_LSTATUS) != 0) { |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 601 | return 1; |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 602 | } else { |
Andy Fleming | 16a5323 | 2011-04-07 14:38:35 -0500 | [diff] [blame] | 603 | return 0; |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | #endif |