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