Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 1 | /* MDIO Bus interface |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 2 | * |
| 3 | * Author: Andy Fleming |
| 4 | * |
| 5 | * Copyright (c) 2004 Freescale Semiconductor, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | */ |
Joe Perches | 8d24248 | 2012-06-09 07:49:07 +0000 | [diff] [blame] | 13 | |
| 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 17 | #include <linux/string.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/delay.h> |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 24 | #include <linux/device.h> |
David Daney | a30e2c1 | 2012-06-27 07:33:37 +0000 | [diff] [blame] | 25 | #include <linux/of_device.h> |
Mark Brown | 4085a7f | 2012-10-08 22:55:43 +0000 | [diff] [blame] | 26 | #include <linux/of_mdio.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/module.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 33 | #include <linux/mii.h> |
| 34 | #include <linux/ethtool.h> |
| 35 | #include <linux/phy.h> |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 36 | #include <linux/io.h> |
| 37 | #include <linux/uaccess.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 38 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 39 | #include <asm/irq.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 40 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 41 | /** |
Timur Tabi | eb8a54a7 | 2012-01-12 15:23:04 -0800 | [diff] [blame] | 42 | * mdiobus_alloc_size - allocate a mii_bus structure |
Randy Dunlap | af58f1d | 2012-01-21 09:03:04 +0000 | [diff] [blame] | 43 | * @size: extra amount of memory to allocate for private storage. |
| 44 | * If non-zero, then bus->priv is points to that memory. |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 45 | * |
| 46 | * Description: called by a bus driver to allocate an mii_bus |
| 47 | * structure to fill in. |
| 48 | */ |
Timur Tabi | eb8a54a7 | 2012-01-12 15:23:04 -0800 | [diff] [blame] | 49 | struct mii_bus *mdiobus_alloc_size(size_t size) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 50 | { |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 51 | struct mii_bus *bus; |
Timur Tabi | eb8a54a7 | 2012-01-12 15:23:04 -0800 | [diff] [blame] | 52 | size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN); |
| 53 | size_t alloc_size; |
Andrew Lunn | e7f4dc3 | 2016-01-06 20:11:15 +0100 | [diff] [blame] | 54 | int i; |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 55 | |
Timur Tabi | eb8a54a7 | 2012-01-12 15:23:04 -0800 | [diff] [blame] | 56 | /* If we alloc extra space, it should be aligned */ |
| 57 | if (size) |
| 58 | alloc_size = aligned_size + size; |
| 59 | else |
| 60 | alloc_size = sizeof(*bus); |
| 61 | |
| 62 | bus = kzalloc(alloc_size, GFP_KERNEL); |
| 63 | if (bus) { |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 64 | bus->state = MDIOBUS_ALLOCATED; |
Timur Tabi | eb8a54a7 | 2012-01-12 15:23:04 -0800 | [diff] [blame] | 65 | if (size) |
| 66 | bus->priv = (void *)bus + aligned_size; |
| 67 | } |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 68 | |
Andrew Lunn | e7f4dc3 | 2016-01-06 20:11:15 +0100 | [diff] [blame] | 69 | /* Initialise the interrupts to polling */ |
| 70 | for (i = 0; i < PHY_MAX_ADDR; i++) |
| 71 | bus->irq[i] = PHY_POLL; |
| 72 | |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 73 | return bus; |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 74 | } |
Timur Tabi | eb8a54a7 | 2012-01-12 15:23:04 -0800 | [diff] [blame] | 75 | EXPORT_SYMBOL(mdiobus_alloc_size); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 76 | |
Grygorii Strashko | 6d48f44 | 2014-04-30 15:23:33 +0300 | [diff] [blame] | 77 | static void _devm_mdiobus_free(struct device *dev, void *res) |
| 78 | { |
| 79 | mdiobus_free(*(struct mii_bus **)res); |
| 80 | } |
| 81 | |
| 82 | static int devm_mdiobus_match(struct device *dev, void *res, void *data) |
| 83 | { |
| 84 | struct mii_bus **r = res; |
| 85 | |
| 86 | if (WARN_ON(!r || !*r)) |
| 87 | return 0; |
| 88 | |
| 89 | return *r == data; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * devm_mdiobus_alloc_size - Resource-managed mdiobus_alloc_size() |
| 94 | * @dev: Device to allocate mii_bus for |
| 95 | * @sizeof_priv: Space to allocate for private structure. |
| 96 | * |
| 97 | * Managed mdiobus_alloc_size. mii_bus allocated with this function is |
| 98 | * automatically freed on driver detach. |
| 99 | * |
| 100 | * If an mii_bus allocated with this function needs to be freed separately, |
| 101 | * devm_mdiobus_free() must be used. |
| 102 | * |
| 103 | * RETURNS: |
| 104 | * Pointer to allocated mii_bus on success, NULL on failure. |
| 105 | */ |
| 106 | struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv) |
| 107 | { |
| 108 | struct mii_bus **ptr, *bus; |
| 109 | |
| 110 | ptr = devres_alloc(_devm_mdiobus_free, sizeof(*ptr), GFP_KERNEL); |
| 111 | if (!ptr) |
| 112 | return NULL; |
| 113 | |
| 114 | /* use raw alloc_dr for kmalloc caller tracing */ |
| 115 | bus = mdiobus_alloc_size(sizeof_priv); |
| 116 | if (bus) { |
| 117 | *ptr = bus; |
| 118 | devres_add(dev, ptr); |
| 119 | } else { |
| 120 | devres_free(ptr); |
| 121 | } |
| 122 | |
| 123 | return bus; |
| 124 | } |
Arnd Bergmann | 93dccc5 | 2014-05-08 16:46:52 +0200 | [diff] [blame] | 125 | EXPORT_SYMBOL_GPL(devm_mdiobus_alloc_size); |
Grygorii Strashko | 6d48f44 | 2014-04-30 15:23:33 +0300 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * devm_mdiobus_free - Resource-managed mdiobus_free() |
| 129 | * @dev: Device this mii_bus belongs to |
| 130 | * @bus: the mii_bus associated with the device |
| 131 | * |
| 132 | * Free mii_bus allocated with devm_mdiobus_alloc_size(). |
| 133 | */ |
| 134 | void devm_mdiobus_free(struct device *dev, struct mii_bus *bus) |
| 135 | { |
| 136 | int rc; |
| 137 | |
| 138 | rc = devres_release(dev, _devm_mdiobus_free, |
| 139 | devm_mdiobus_match, bus); |
| 140 | WARN_ON(rc); |
| 141 | } |
| 142 | EXPORT_SYMBOL_GPL(devm_mdiobus_free); |
| 143 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 144 | /** |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 145 | * mdiobus_release - mii_bus device release callback |
Randy Dunlap | 78c36b1 | 2008-10-13 18:46:22 -0700 | [diff] [blame] | 146 | * @d: the target struct device that contains the mii_bus |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 147 | * |
| 148 | * Description: called when the last reference to an mii_bus is |
| 149 | * dropped, to free the underlying memory. |
| 150 | */ |
| 151 | static void mdiobus_release(struct device *d) |
| 152 | { |
| 153 | struct mii_bus *bus = to_mii_bus(d); |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 154 | BUG_ON(bus->state != MDIOBUS_RELEASED && |
| 155 | /* for compatibility with error handling in drivers */ |
| 156 | bus->state != MDIOBUS_ALLOCATED); |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 157 | kfree(bus); |
| 158 | } |
| 159 | |
| 160 | static struct class mdio_bus_class = { |
| 161 | .name = "mdio_bus", |
| 162 | .dev_release = mdiobus_release, |
| 163 | }; |
| 164 | |
Bjørn Mork | b943fbb | 2012-05-11 05:47:01 +0000 | [diff] [blame] | 165 | #if IS_ENABLED(CONFIG_OF_MDIO) |
David Daney | 2510602 | 2012-05-02 15:16:37 +0000 | [diff] [blame] | 166 | /* Helper function for of_mdio_find_bus */ |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 167 | static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np) |
David Daney | 2510602 | 2012-05-02 15:16:37 +0000 | [diff] [blame] | 168 | { |
| 169 | return dev->of_node == mdio_bus_np; |
| 170 | } |
| 171 | /** |
| 172 | * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. |
Randy Dunlap | f41ef2e | 2012-06-08 14:07:19 +0000 | [diff] [blame] | 173 | * @mdio_bus_np: Pointer to the mii_bus. |
David Daney | 2510602 | 2012-05-02 15:16:37 +0000 | [diff] [blame] | 174 | * |
Russell King | a136442 | 2015-09-24 20:35:52 +0100 | [diff] [blame] | 175 | * Returns a reference to the mii_bus, or NULL if none found. The |
| 176 | * embedded struct device will have its reference count incremented, |
| 177 | * and this must be put once the bus is finished with. |
David Daney | 2510602 | 2012-05-02 15:16:37 +0000 | [diff] [blame] | 178 | * |
| 179 | * Because the association of a device_node and mii_bus is made via |
| 180 | * of_mdiobus_register(), the mii_bus cannot be found before it is |
| 181 | * registered with of_mdiobus_register(). |
| 182 | * |
| 183 | */ |
| 184 | struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np) |
| 185 | { |
| 186 | struct device *d; |
| 187 | |
| 188 | if (!mdio_bus_np) |
| 189 | return NULL; |
| 190 | |
| 191 | d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np, |
| 192 | of_mdio_bus_match); |
| 193 | |
| 194 | return d ? to_mii_bus(d) : NULL; |
| 195 | } |
| 196 | EXPORT_SYMBOL(of_mdio_find_bus); |
Daniel Mack | d9daa24 | 2014-06-28 01:23:35 +0200 | [diff] [blame] | 197 | |
| 198 | /* Walk the list of subnodes of a mdio bus and look for a node that matches the |
| 199 | * phy's address with its 'reg' property. If found, set the of_node pointer for |
| 200 | * the phy. This allows auto-probed pyh devices to be supplied with information |
| 201 | * passed in via DT. |
| 202 | */ |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame^] | 203 | static void of_mdiobus_link_phydev(struct mii_bus *bus, |
Daniel Mack | d9daa24 | 2014-06-28 01:23:35 +0200 | [diff] [blame] | 204 | struct phy_device *phydev) |
| 205 | { |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame^] | 206 | struct device *dev = &phydev->mdio.dev; |
Daniel Mack | d9daa24 | 2014-06-28 01:23:35 +0200 | [diff] [blame] | 207 | struct device_node *child; |
| 208 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame^] | 209 | if (dev->of_node || !bus->dev.of_node) |
Daniel Mack | d9daa24 | 2014-06-28 01:23:35 +0200 | [diff] [blame] | 210 | return; |
| 211 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame^] | 212 | for_each_available_child_of_node(bus->dev.of_node, child) { |
Daniel Mack | d9daa24 | 2014-06-28 01:23:35 +0200 | [diff] [blame] | 213 | int addr; |
| 214 | int ret; |
| 215 | |
| 216 | ret = of_property_read_u32(child, "reg", &addr); |
| 217 | if (ret < 0) { |
| 218 | dev_err(dev, "%s has invalid PHY address\n", |
| 219 | child->full_name); |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | /* A PHY must have a reg property in the range [0-31] */ |
| 224 | if (addr >= PHY_MAX_ADDR) { |
| 225 | dev_err(dev, "%s PHY address %i is too large\n", |
| 226 | child->full_name, addr); |
| 227 | continue; |
| 228 | } |
| 229 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame^] | 230 | if (addr == phydev->mdio.addr) { |
Daniel Mack | d9daa24 | 2014-06-28 01:23:35 +0200 | [diff] [blame] | 231 | dev->of_node = child; |
| 232 | return; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | #else /* !IS_ENABLED(CONFIG_OF_MDIO) */ |
| 237 | static inline void of_mdiobus_link_phydev(struct mii_bus *mdio, |
| 238 | struct phy_device *phydev) |
| 239 | { |
| 240 | } |
David Daney | 2510602 | 2012-05-02 15:16:37 +0000 | [diff] [blame] | 241 | #endif |
| 242 | |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 243 | /** |
Russell King | 59f0697 | 2015-09-25 11:56:56 +0100 | [diff] [blame] | 244 | * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 245 | * @bus: target mii_bus |
Russell King | 59f0697 | 2015-09-25 11:56:56 +0100 | [diff] [blame] | 246 | * @owner: module containing bus accessor functions |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 247 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 248 | * Description: Called by a bus driver to bring up all the PHYs |
Russell King | 59f0697 | 2015-09-25 11:56:56 +0100 | [diff] [blame] | 249 | * on a given bus, and attach them to the bus. Drivers should use |
| 250 | * mdiobus_register() rather than __mdiobus_register() unless they |
| 251 | * need to pass a specific owner module. |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 252 | * |
| 253 | * Returns 0 on success or < 0 on error. |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 254 | */ |
Russell King | 3e3aaf6 | 2015-09-24 20:36:02 +0100 | [diff] [blame] | 255 | int __mdiobus_register(struct mii_bus *bus, struct module *owner) |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 256 | { |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 257 | int i, err; |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 258 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 259 | if (NULL == bus || NULL == bus->name || |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 260 | NULL == bus->read || NULL == bus->write) |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 261 | return -EINVAL; |
| 262 | |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 263 | BUG_ON(bus->state != MDIOBUS_ALLOCATED && |
| 264 | bus->state != MDIOBUS_UNREGISTERED); |
| 265 | |
Russell King | 3e3aaf6 | 2015-09-24 20:36:02 +0100 | [diff] [blame] | 266 | bus->owner = owner; |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 267 | bus->dev.parent = bus->parent; |
| 268 | bus->dev.class = &mdio_bus_class; |
| 269 | bus->dev.groups = NULL; |
Stephen Hemminger | 036b668 | 2009-02-26 10:19:36 +0000 | [diff] [blame] | 270 | dev_set_name(&bus->dev, "%s", bus->id); |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 271 | |
| 272 | err = device_register(&bus->dev); |
| 273 | if (err) { |
Joe Perches | 8d24248 | 2012-06-09 07:49:07 +0000 | [diff] [blame] | 274 | pr_err("mii_bus %s failed to register\n", bus->id); |
Levente Kurusa | 0c692d0 | 2014-01-30 15:45:46 -0800 | [diff] [blame] | 275 | put_device(&bus->dev); |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 276 | return -EINVAL; |
| 277 | } |
| 278 | |
Adrian Bunk | d1e7fe4 | 2008-02-20 02:13:53 +0200 | [diff] [blame] | 279 | mutex_init(&bus->mdio_lock); |
| 280 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 281 | if (bus->reset) |
| 282 | bus->reset(bus); |
| 283 | |
| 284 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 285 | if ((bus->phy_mask & (1 << i)) == 0) { |
| 286 | struct phy_device *phydev; |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 287 | |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 288 | phydev = mdiobus_scan(bus, i); |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 289 | if (IS_ERR(phydev)) { |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 290 | err = PTR_ERR(phydev); |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 291 | goto error; |
| 292 | } |
Herbert Valerio Riedel | 64b1c2b | 2006-05-10 12:12:57 -0400 | [diff] [blame] | 293 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 296 | bus->state = MDIOBUS_REGISTERED; |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 297 | pr_info("%s: probed\n", bus->name); |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 298 | return 0; |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 299 | |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 300 | error: |
| 301 | while (--i >= 0) { |
Russell King | 38737e4 | 2015-09-24 20:36:28 +0100 | [diff] [blame] | 302 | struct phy_device *phydev = bus->phy_map[i]; |
| 303 | if (phydev) { |
| 304 | phy_device_remove(phydev); |
| 305 | phy_device_free(phydev); |
| 306 | } |
Krzysztof Halasa | 161c8d2 | 2008-12-25 16:50:41 -0800 | [diff] [blame] | 307 | } |
| 308 | device_del(&bus->dev); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 309 | return err; |
| 310 | } |
Russell King | 3e3aaf6 | 2015-09-24 20:36:02 +0100 | [diff] [blame] | 311 | EXPORT_SYMBOL(__mdiobus_register); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 312 | |
| 313 | void mdiobus_unregister(struct mii_bus *bus) |
| 314 | { |
| 315 | int i; |
| 316 | |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 317 | BUG_ON(bus->state != MDIOBUS_REGISTERED); |
| 318 | bus->state = MDIOBUS_UNREGISTERED; |
| 319 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 320 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
Russell King | 38737e4 | 2015-09-24 20:36:28 +0100 | [diff] [blame] | 321 | struct phy_device *phydev = bus->phy_map[i]; |
| 322 | if (phydev) { |
| 323 | phy_device_remove(phydev); |
| 324 | phy_device_free(phydev); |
| 325 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 326 | } |
Mark Salter | b6c6aed | 2015-09-01 09:36:05 -0400 | [diff] [blame] | 327 | device_del(&bus->dev); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 328 | } |
| 329 | EXPORT_SYMBOL(mdiobus_unregister); |
| 330 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 331 | /** |
| 332 | * mdiobus_free - free a struct mii_bus |
| 333 | * @bus: mii_bus to free |
| 334 | * |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 335 | * This function releases the reference to the underlying device |
| 336 | * object in the mii_bus. If this is the last reference, the mii_bus |
| 337 | * will be freed. |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 338 | */ |
| 339 | void mdiobus_free(struct mii_bus *bus) |
| 340 | { |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 341 | /* For compatibility with error handling in drivers. */ |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 342 | if (bus->state == MDIOBUS_ALLOCATED) { |
| 343 | kfree(bus); |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | BUG_ON(bus->state != MDIOBUS_UNREGISTERED); |
| 348 | bus->state = MDIOBUS_RELEASED; |
| 349 | |
| 350 | put_device(&bus->dev); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 351 | } |
| 352 | EXPORT_SYMBOL(mdiobus_free); |
| 353 | |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 354 | struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) |
| 355 | { |
| 356 | struct phy_device *phydev; |
| 357 | int err; |
| 358 | |
David Daney | ac28b9f | 2012-06-27 07:33:35 +0000 | [diff] [blame] | 359 | phydev = get_phy_device(bus, addr, false); |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 360 | if (IS_ERR(phydev) || phydev == NULL) |
| 361 | return phydev; |
| 362 | |
Daniel Mack | 86f6cf4 | 2014-05-24 09:34:26 +0200 | [diff] [blame] | 363 | /* |
| 364 | * For DT, see if the auto-probed phy has a correspoding child |
| 365 | * in the bus node, and set the of_node pointer in this case. |
| 366 | */ |
| 367 | of_mdiobus_link_phydev(bus, phydev); |
| 368 | |
Grant Likely | 4dea547 | 2009-04-25 12:52:46 +0000 | [diff] [blame] | 369 | err = phy_device_register(phydev); |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 370 | if (err) { |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 371 | phy_device_free(phydev); |
Grant Likely | 4dea547 | 2009-04-25 12:52:46 +0000 | [diff] [blame] | 372 | return NULL; |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Lennert Buytenhek | 4fd5f81 | 2008-08-26 13:08:46 +0200 | [diff] [blame] | 375 | return phydev; |
| 376 | } |
| 377 | EXPORT_SYMBOL(mdiobus_scan); |
| 378 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 379 | /** |
Neil Armstrong | 21dd19f | 2015-10-22 10:37:49 +0200 | [diff] [blame] | 380 | * mdiobus_read_nested - Nested version of the mdiobus_read function |
| 381 | * @bus: the mii_bus struct |
| 382 | * @addr: the phy address |
| 383 | * @regnum: register number to read |
| 384 | * |
| 385 | * In case of nested MDIO bus access avoid lockdep false positives by |
| 386 | * using mutex_lock_nested(). |
| 387 | * |
| 388 | * NOTE: MUST NOT be called from interrupt context, |
| 389 | * because the bus read/write functions may wait for an interrupt |
| 390 | * to conclude the operation. |
| 391 | */ |
| 392 | int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum) |
| 393 | { |
| 394 | int retval; |
| 395 | |
| 396 | BUG_ON(in_interrupt()); |
| 397 | |
| 398 | mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING); |
| 399 | retval = bus->read(bus, addr, regnum); |
| 400 | mutex_unlock(&bus->mdio_lock); |
| 401 | |
| 402 | return retval; |
| 403 | } |
| 404 | EXPORT_SYMBOL(mdiobus_read_nested); |
| 405 | |
| 406 | /** |
Lennert Buytenhek | 2e88810 | 2008-09-29 17:12:35 +0000 | [diff] [blame] | 407 | * mdiobus_read - Convenience function for reading a given MII mgmt register |
| 408 | * @bus: the mii_bus struct |
| 409 | * @addr: the phy address |
| 410 | * @regnum: register number to read |
| 411 | * |
| 412 | * NOTE: MUST NOT be called from interrupt context, |
| 413 | * because the bus read/write functions may wait for an interrupt |
| 414 | * to conclude the operation. |
| 415 | */ |
Jason Gunthorpe | abf35df | 2010-03-09 09:17:42 +0000 | [diff] [blame] | 416 | int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) |
Lennert Buytenhek | 2e88810 | 2008-09-29 17:12:35 +0000 | [diff] [blame] | 417 | { |
| 418 | int retval; |
| 419 | |
| 420 | BUG_ON(in_interrupt()); |
| 421 | |
| 422 | mutex_lock(&bus->mdio_lock); |
| 423 | retval = bus->read(bus, addr, regnum); |
| 424 | mutex_unlock(&bus->mdio_lock); |
| 425 | |
| 426 | return retval; |
| 427 | } |
| 428 | EXPORT_SYMBOL(mdiobus_read); |
| 429 | |
| 430 | /** |
Neil Armstrong | 21dd19f | 2015-10-22 10:37:49 +0200 | [diff] [blame] | 431 | * mdiobus_write_nested - Nested version of the mdiobus_write function |
| 432 | * @bus: the mii_bus struct |
| 433 | * @addr: the phy address |
| 434 | * @regnum: register number to write |
| 435 | * @val: value to write to @regnum |
| 436 | * |
| 437 | * In case of nested MDIO bus access avoid lockdep false positives by |
| 438 | * using mutex_lock_nested(). |
| 439 | * |
| 440 | * NOTE: MUST NOT be called from interrupt context, |
| 441 | * because the bus read/write functions may wait for an interrupt |
| 442 | * to conclude the operation. |
| 443 | */ |
| 444 | int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val) |
| 445 | { |
| 446 | int err; |
| 447 | |
| 448 | BUG_ON(in_interrupt()); |
| 449 | |
| 450 | mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING); |
| 451 | err = bus->write(bus, addr, regnum, val); |
| 452 | mutex_unlock(&bus->mdio_lock); |
| 453 | |
| 454 | return err; |
| 455 | } |
| 456 | EXPORT_SYMBOL(mdiobus_write_nested); |
| 457 | |
| 458 | /** |
Lennert Buytenhek | 2e88810 | 2008-09-29 17:12:35 +0000 | [diff] [blame] | 459 | * mdiobus_write - Convenience function for writing a given MII mgmt register |
| 460 | * @bus: the mii_bus struct |
| 461 | * @addr: the phy address |
| 462 | * @regnum: register number to write |
| 463 | * @val: value to write to @regnum |
| 464 | * |
| 465 | * NOTE: MUST NOT be called from interrupt context, |
| 466 | * because the bus read/write functions may wait for an interrupt |
| 467 | * to conclude the operation. |
| 468 | */ |
Jason Gunthorpe | abf35df | 2010-03-09 09:17:42 +0000 | [diff] [blame] | 469 | int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) |
Lennert Buytenhek | 2e88810 | 2008-09-29 17:12:35 +0000 | [diff] [blame] | 470 | { |
| 471 | int err; |
| 472 | |
| 473 | BUG_ON(in_interrupt()); |
| 474 | |
| 475 | mutex_lock(&bus->mdio_lock); |
| 476 | err = bus->write(bus, addr, regnum, val); |
| 477 | mutex_unlock(&bus->mdio_lock); |
| 478 | |
| 479 | return err; |
| 480 | } |
| 481 | EXPORT_SYMBOL(mdiobus_write); |
| 482 | |
| 483 | /** |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 484 | * mdio_bus_match - determine if given PHY driver supports the given PHY device |
| 485 | * @dev: target PHY device |
| 486 | * @drv: given PHY driver |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 487 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 488 | * Description: Given a PHY device, and a PHY driver, return 1 if |
| 489 | * the driver supports the device. Otherwise, return 0. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 490 | */ |
| 491 | static int mdio_bus_match(struct device *dev, struct device_driver *drv) |
| 492 | { |
| 493 | struct phy_device *phydev = to_phy_device(dev); |
| 494 | struct phy_driver *phydrv = to_phy_driver(drv); |
Shaohui Xie | e0536cd | 2015-07-17 18:07:19 +0800 | [diff] [blame] | 495 | const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids); |
| 496 | int i; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 497 | |
David Daney | a30e2c1 | 2012-06-27 07:33:37 +0000 | [diff] [blame] | 498 | if (of_driver_match_device(dev, drv)) |
| 499 | return 1; |
| 500 | |
| 501 | if (phydrv->match_phy_device) |
| 502 | return phydrv->match_phy_device(phydev); |
| 503 | |
Shaohui Xie | e0536cd | 2015-07-17 18:07:19 +0800 | [diff] [blame] | 504 | if (phydev->is_c45) { |
| 505 | for (i = 1; i < num_ids; i++) { |
| 506 | if (!(phydev->c45_ids.devices_in_package & (1 << i))) |
| 507 | continue; |
| 508 | |
| 509 | if ((phydrv->phy_id & phydrv->phy_id_mask) == |
| 510 | (phydev->c45_ids.device_ids[i] & |
| 511 | phydrv->phy_id_mask)) |
| 512 | return 1; |
| 513 | } |
| 514 | return 0; |
| 515 | } else { |
| 516 | return (phydrv->phy_id & phydrv->phy_id_mask) == |
| 517 | (phydev->phy_id & phydrv->phy_id_mask); |
| 518 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 521 | #ifdef CONFIG_PM |
| 522 | |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 523 | static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) |
| 524 | { |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame^] | 525 | struct device_driver *drv = phydev->mdio.dev.driver; |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 526 | struct phy_driver *phydrv = to_phy_driver(drv); |
| 527 | struct net_device *netdev = phydev->attached_dev; |
| 528 | |
| 529 | if (!drv || !phydrv->suspend) |
| 530 | return false; |
| 531 | |
Florian Fainelli | 803dd9c | 2015-01-26 22:05:40 -0800 | [diff] [blame] | 532 | /* PHY not attached? May suspend if the PHY has not already been |
| 533 | * suspended as part of a prior call to phy_disconnect() -> |
| 534 | * phy_detach() -> phy_suspend() because the parent netdev might be the |
| 535 | * MDIO bus driver and clock gated at this point. |
| 536 | */ |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 537 | if (!netdev) |
Florian Fainelli | 803dd9c | 2015-01-26 22:05:40 -0800 | [diff] [blame] | 538 | return !phydev->suspended; |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 539 | |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 540 | /* Don't suspend PHY if the attched netdev parent may wakeup. |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 541 | * The parent may point to a PCI device, as in tg3 driver. |
| 542 | */ |
| 543 | if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) |
| 544 | return false; |
| 545 | |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 546 | /* Also don't suspend PHY if the netdev itself may wakeup. This |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 547 | * is the case for devices w/o underlaying pwr. mgmt. aware bus, |
| 548 | * e.g. SoC devices. |
| 549 | */ |
| 550 | if (device_may_wakeup(&netdev->dev)) |
| 551 | return false; |
| 552 | |
| 553 | return true; |
| 554 | } |
| 555 | |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 556 | static int mdio_bus_suspend(struct device *dev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 557 | { |
Giuseppe Cavallaro | 0f0ca34 | 2008-11-28 16:24:56 -0800 | [diff] [blame] | 558 | struct phy_device *phydev = to_phy_device(dev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 559 | |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 560 | /* We must stop the state machine manually, otherwise it stops out of |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 561 | * control, possibly with the phydev->lock held. Upon resume, netdev |
| 562 | * may call phy routines that try to grab the same lock, and that may |
| 563 | * lead to a deadlock. |
| 564 | */ |
Simon Guinot | fddd910 | 2010-09-13 22:12:01 +0000 | [diff] [blame] | 565 | if (phydev->attached_dev && phydev->adjust_link) |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 566 | phy_stop_machine(phydev); |
| 567 | |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 568 | if (!mdio_bus_phy_may_suspend(phydev)) |
| 569 | return 0; |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 570 | |
Florian Fainelli | 9272efa | 2015-01-26 22:05:37 -0800 | [diff] [blame] | 571 | return phy_suspend(phydev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 572 | } |
| 573 | |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 574 | static int mdio_bus_resume(struct device *dev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 575 | { |
Giuseppe Cavallaro | 0f0ca34 | 2008-11-28 16:24:56 -0800 | [diff] [blame] | 576 | struct phy_device *phydev = to_phy_device(dev); |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 577 | int ret; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 578 | |
Anton Vorontsov | 3d1e4db | 2009-02-01 00:53:34 -0800 | [diff] [blame] | 579 | if (!mdio_bus_phy_may_suspend(phydev)) |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 580 | goto no_resume; |
| 581 | |
Florian Fainelli | 9272efa | 2015-01-26 22:05:37 -0800 | [diff] [blame] | 582 | ret = phy_resume(phydev); |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 583 | if (ret < 0) |
| 584 | return ret; |
| 585 | |
| 586 | no_resume: |
Simon Guinot | fddd910 | 2010-09-13 22:12:01 +0000 | [diff] [blame] | 587 | if (phydev->attached_dev && phydev->adjust_link) |
Sergei Shtylyov | 29935ae | 2014-01-05 03:27:17 +0300 | [diff] [blame] | 588 | phy_start_machine(phydev); |
Anton Vorontsov | 541cd3e | 2009-12-30 08:23:28 +0000 | [diff] [blame] | 589 | |
| 590 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 591 | } |
| 592 | |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 593 | static int mdio_bus_restore(struct device *dev) |
| 594 | { |
| 595 | struct phy_device *phydev = to_phy_device(dev); |
| 596 | struct net_device *netdev = phydev->attached_dev; |
| 597 | int ret; |
| 598 | |
| 599 | if (!netdev) |
| 600 | return 0; |
| 601 | |
| 602 | ret = phy_init_hw(phydev); |
| 603 | if (ret < 0) |
| 604 | return ret; |
| 605 | |
| 606 | /* The PHY needs to renegotiate. */ |
| 607 | phydev->link = 0; |
| 608 | phydev->state = PHY_UP; |
| 609 | |
Sergei Shtylyov | 29935ae | 2014-01-05 03:27:17 +0300 | [diff] [blame] | 610 | phy_start_machine(phydev); |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
Sergei Shtylyov | 02d320c | 2014-01-05 03:18:27 +0300 | [diff] [blame] | 615 | static const struct dev_pm_ops mdio_bus_pm_ops = { |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 616 | .suspend = mdio_bus_suspend, |
| 617 | .resume = mdio_bus_resume, |
| 618 | .freeze = mdio_bus_suspend, |
| 619 | .thaw = mdio_bus_resume, |
| 620 | .restore = mdio_bus_restore, |
| 621 | }; |
| 622 | |
| 623 | #define MDIO_BUS_PM_OPS (&mdio_bus_pm_ops) |
| 624 | |
| 625 | #else |
| 626 | |
| 627 | #define MDIO_BUS_PM_OPS NULL |
| 628 | |
| 629 | #endif /* CONFIG_PM */ |
| 630 | |
Nick Bowler | 56277f4 | 2012-11-07 06:20:34 +0000 | [diff] [blame] | 631 | static ssize_t |
| 632 | phy_id_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 633 | { |
| 634 | struct phy_device *phydev = to_phy_device(dev); |
| 635 | |
| 636 | return sprintf(buf, "0x%.8lx\n", (unsigned long)phydev->phy_id); |
| 637 | } |
Greg Kroah-Hartman | 4192c74 | 2013-10-06 23:55:41 -0700 | [diff] [blame] | 638 | static DEVICE_ATTR_RO(phy_id); |
Nick Bowler | 56277f4 | 2012-11-07 06:20:34 +0000 | [diff] [blame] | 639 | |
Florian Fainelli | 3d055d8 | 2014-02-11 17:27:40 -0800 | [diff] [blame] | 640 | static ssize_t |
| 641 | phy_interface_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 642 | { |
| 643 | struct phy_device *phydev = to_phy_device(dev); |
Florian Fainelli | 574746d | 2014-08-27 11:44:33 -0700 | [diff] [blame] | 644 | const char *mode = NULL; |
Florian Fainelli | 3d055d8 | 2014-02-11 17:27:40 -0800 | [diff] [blame] | 645 | |
Florian Fainelli | 574746d | 2014-08-27 11:44:33 -0700 | [diff] [blame] | 646 | if (phy_is_internal(phydev)) |
| 647 | mode = "internal"; |
| 648 | else |
| 649 | mode = phy_modes(phydev->interface); |
| 650 | |
| 651 | return sprintf(buf, "%s\n", mode); |
Florian Fainelli | 3d055d8 | 2014-02-11 17:27:40 -0800 | [diff] [blame] | 652 | } |
| 653 | static DEVICE_ATTR_RO(phy_interface); |
| 654 | |
Florian Fainelli | 8bed1285 | 2014-02-11 17:27:42 -0800 | [diff] [blame] | 655 | static ssize_t |
| 656 | phy_has_fixups_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 657 | { |
| 658 | struct phy_device *phydev = to_phy_device(dev); |
| 659 | |
| 660 | return sprintf(buf, "%d\n", phydev->has_fixups); |
| 661 | } |
| 662 | static DEVICE_ATTR_RO(phy_has_fixups); |
| 663 | |
Greg Kroah-Hartman | 4192c74 | 2013-10-06 23:55:41 -0700 | [diff] [blame] | 664 | static struct attribute *mdio_dev_attrs[] = { |
| 665 | &dev_attr_phy_id.attr, |
Florian Fainelli | 3d055d8 | 2014-02-11 17:27:40 -0800 | [diff] [blame] | 666 | &dev_attr_phy_interface.attr, |
Florian Fainelli | 8bed1285 | 2014-02-11 17:27:42 -0800 | [diff] [blame] | 667 | &dev_attr_phy_has_fixups.attr, |
Greg Kroah-Hartman | 4192c74 | 2013-10-06 23:55:41 -0700 | [diff] [blame] | 668 | NULL, |
Nick Bowler | 56277f4 | 2012-11-07 06:20:34 +0000 | [diff] [blame] | 669 | }; |
Greg Kroah-Hartman | 4192c74 | 2013-10-06 23:55:41 -0700 | [diff] [blame] | 670 | ATTRIBUTE_GROUPS(mdio_dev); |
Nick Bowler | 56277f4 | 2012-11-07 06:20:34 +0000 | [diff] [blame] | 671 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 672 | struct bus_type mdio_bus_type = { |
| 673 | .name = "mdio_bus", |
| 674 | .match = mdio_bus_match, |
Anton Vorontsov | 2f5cb43 | 2009-12-30 08:23:30 +0000 | [diff] [blame] | 675 | .pm = MDIO_BUS_PM_OPS, |
Greg Kroah-Hartman | 4192c74 | 2013-10-06 23:55:41 -0700 | [diff] [blame] | 676 | .dev_groups = mdio_dev_groups, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 677 | }; |
Vitaly Bordug | 11b0bac | 2006-08-14 23:00:29 -0700 | [diff] [blame] | 678 | EXPORT_SYMBOL(mdio_bus_type); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 679 | |
Jeff Garzik | 67c4f3f | 2005-08-11 02:07:25 -0400 | [diff] [blame] | 680 | int __init mdio_bus_init(void) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 681 | { |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 682 | int ret; |
| 683 | |
| 684 | ret = class_register(&mdio_bus_class); |
| 685 | if (!ret) { |
| 686 | ret = bus_register(&mdio_bus_type); |
| 687 | if (ret) |
| 688 | class_unregister(&mdio_bus_class); |
| 689 | } |
| 690 | |
| 691 | return ret; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 692 | } |
| 693 | |
Peter Chubb | dc85dec | 2005-09-03 14:05:06 -0700 | [diff] [blame] | 694 | void mdio_bus_exit(void) |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 695 | { |
Lennert Buytenhek | 46abc02 | 2008-10-08 16:33:40 -0700 | [diff] [blame] | 696 | class_unregister(&mdio_bus_class); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 697 | bus_unregister(&mdio_bus_type); |
| 698 | } |